developer tip

C # 코드가 컴파일되지 않습니다.

copycodes 2020. 10. 6. 08:23
반응형

C # 코드가 컴파일되지 않습니다. null과 int 사이의 암시 적 변환 없음 [중복]


중복 가능성 :
Nullable 유형과 삼항 연산자 : 왜`? 10 : null` 금지?

왜 이것이 작동하지 않습니까? 유효한 코드처럼 보입니다.

  string cert = ddCovCert.SelectedValue;
  int? x = (string.IsNullOrEmpty(cert)) ? null: int.Parse(cert);
  Display(x);

어떻게 코딩해야합니까? 이 메서드는 Nullable을 사용합니다. 드롭 다운에 선택된 문자열이 있으면 int로 구문 분석해야합니다. 그렇지 않으면 null을 메서드에 전달하고 싶습니다.


int? x = string.IsNullOrEmpty(cert) ? (int?)null : int.Parse(cert);

나는 똑같은 것을 보았습니다 ... 나는 보통 null을 (int?)

int? x = (string.IsNullOrEmpty(cert)) ? (int?)null: int.Parse(cert);

참고 URL : https://stackoverflow.com/questions/1279046/c-sharp-code-wont-compile-no-implicit-conversion-between-null-and-int

반응형