Extension method to check if a Nullable Datetime has value or not. If it has value then return that else return default value using C#?

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 1271
The below will do so -

public static class ClassExtensions
{
public static DateTime GetProperDate(this DateTime? dt)
{
return dt.HasValue ? dt.Value : new DateTime(1900, 1, 1);
}
}

Comments or Responses

Login to post response