가능한 중복 : 예를 들어
Nullable types and the ternary operator. Why won’t this work?C# nullable 형식의 질문
:
int? taxid;
if (ddlProductTax.SelectedValue == "") {
taxid = null; }
else {
taxid = Convert.ToInt32(ddlProductTax.SelectedValue);
} //Correct
그러나
int? taxid;
taxid = (ddlProductTax.SelectedValue == "" ? null : Convert.ToInt32(ddlProductTax.SelectedValue)); //Error
오류가 발생했으며 int32는 암시 적 변환을 할 수 없습니다.
(? truepart : falsepart); ... (만약 ..) .. 부족하다?
@Gishu, 정확한 내가 말하고 싶지만 중복. @TatMing은 연결된 복제물에 대한 응답을 확인합니다. – Paolo
에릭 리 퍼트 (Eric Lippert)가 최근 블로그 게시물 [http://blogs.msdn.com/b/ericlippert/archive/2010/05/27/cast-operators-do-not-obey-the-distributive-law. aspx] (http://blogs.msdn.com/b/ericlippert/archive/2010/05/27/cast-operators-do-not-obey-the-distributive-law.aspx) – benPearce