How does cast in C#/.NET 3.5 work for types with '?'
- by Inez
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 compiler error:
Error 1 Type of conditional expression cannot be determined because there is no implicit conversion between 'decimal' and '<null>'
I wonder why? any ideas?