You can use the GetValueOrDefault() function in Nullable.
return id.GetValueOrDefault(0); // Or whatever default value is wise to use...
Note that this is similar to Richard77's coalescing answer , but I would say a little more readable ...
However, deciding whether this is a good idea is up to you. Perhaps an exception is more appropriate?
if (! id.HasValue) throw new Exception("Value not found");
Reddog
source share