반응형
C # 코드가 컴파일되지 않습니다. null과 int 사이의 암시 적 변환 없음 [중복]
왜 이것이 작동하지 않습니까? 유효한 코드처럼 보입니다.
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);
반응형
'developer tip' 카테고리의 다른 글
MVC, C # 및 jQuery를 사용하여 CSV로 내보내기 (0) | 2020.10.06 |
---|---|
웹 서버가없는 스프링 부트 (0) | 2020.10.06 |
Firebase 용 Cloud Functions로 업로드 된 파일에서 다운로드 URL 가져 오기 (0) | 2020.10.06 |
항상 다음 정수로 반올림하는 방법 (0) | 2020.10.06 |
Console.WriteLine ()과 Debug.WriteLine ()의 차이점은 무엇입니까? (0) | 2020.10.05 |