Nullable types can sometimes be a handful to work with. This 'billion dollar mistake' (as described by Tony Hoare who claims to have invented null) can, however, be convereted to r There is a need way of converting nullable type: ??
.
The example below selects some value from an object using Select
method. YourVariable
is nullable. If the value points to something than this value is taken, otherwise 0 is assumed.
1 |
return query.Select(t => t.YourVariable ?? 0).Take(7).ToArray(); |