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

Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 1112
The below will do so -

Public NotInheritable Class ClassExtensions
Private Sub New()
End Sub
<System.Runtime.CompilerServices.Extension> _
Public Shared Function GetProperDate(dt As System.Nullable(Of DateTime)) As DateTime
Return If(dt.HasValue, dt.Value, New DateTime(1900, 1, 1))
End Function
End Class

Comments or Responses

Login to post response