How cast in c#/.net 3.5 works? for types with '?'

Posted by Inez on Stack Overflow See other posts from Stack Overflow or by Inez
Published on 2010-06-09T15:53:31Z Indexed on 2010/06/09 16:02 UTC
Read the original article Hit count: 215

Filed under:
|

This is my code which works

public decimal? Get()
{
    var res = ...
    return res.Count() > 0 ? res.First() : (decimal?) null;
}

and this one doesn't work

public decimal? Get()
{
    var res = ...
    return res.Count() > 0 ? res.First() : null;
}

giving the compilator error: Error 1 Type of conditional expression cannot be determined because there is no implicit conversion between 'decimal' and ''

I wonder why? any ideas?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ