Why can't I set a nullable int to null in a ternary if statement?

Posted by Abe Miessler on Stack Overflow See other posts from Stack Overflow or by Abe Miessler
Published on 2010-05-04T16:06:09Z Indexed on 2010/05/04 16:08 UTC
Read the original article Hit count: 221

Filed under:
|

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 '' and 'int'

Shouldn't this be valid? What am i missing here?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#