If I have a query that returns a DateTime, what’s the value of FirstOrDefault()? Is there a generic way to get the default value of a C# scalar? Example:
var list = (from item in db.Items
where item.ID==1234
select item.StartDate).FirstOrDefault();
Edit: Assume that the column StartDate can’t be null.
The generic way to get a default value for a given generic type is:
where
Tis the generic type parameter in question. For reference types, this will yieldnull. For value types, this will yield a zero’d instance of the value. ForDateTimes, this will be equivalent toDateTime.MinValue.