As I understand it, in Linq the method FirstOrDefault() can return a Default value of something other than null. What I haven’t worked out is what kind of things other than null can be returned by this (and similar) method when there are no items in the query result. Is there any particular way that this can be set up so that if there is no value for a particular query some predefined value is returned as the default value?
As I understand it, in Linq the method FirstOrDefault() can return a Default value
Share
General case, not just for value types:
Again, this can’t really tell if there was anything in your sequence, or if the first value was the default.
If you care about this, you could do something like
and use as
although as Mr. Steak points out this could be done just as well by
.DefaultIfEmpty(...).First().