When getting SQL DateTime Resharper suggests to use new DateTime() when value is DBNull.Value. I’ve always used DateTime.MinValue. Which is the proper way?
DateTime varData = sqlQueryResult["Data"] is DateTime ? (DateTime) sqlQueryResult["Data"] : new DateTime();
From the documentation of DateTime.MinValue:
Thus, the resulting date will be the same. Since
DateTimeis a value type, both options should be equivalent. Personally, I prefer to writeDateTime.MinValue, since it’s self-documenting.PS: You might want to consider using nullable types (
DateTime?), if your data can contain (meaningful) null values.