The C# code below:
int? i;
i = (true ? null : 0);
gives me the error:
Type of conditional expression cannot
be determined because there is no
implicit conversion between ‘<null>’
and ‘int’
Shouldn’t this be valid? What am i missing here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The compiler tries to evaluate the right-hand expression.
nullisnulland the0is anintliteral, notint?. The compiler is trying to tell you that it can’t determine what type the expression should evaluate as. There’s no implicit conversion betweennullandint, hence the error message.You need to tell the compiler that the expression should evaluate as an
int?. There is an implicit conversion betweenint?andint, or betweennullandint?, so either of these should work: