Auto Ad Code

Showing posts with label IsDate. Show all posts
Showing posts with label IsDate. Show all posts

Tuesday, August 3, 2010

IsDate() for C# (C Sharp)

As we all know that IsDate() is a function of VB .Net which checks that either a provided object is date or not. Naturally we all think that the same function will be there in C# (C Sharp) as well but this is not the case.
Following is a simple IsDate() function for C# (C Sharp) which acts exactly like VB .Net
=====================================


public static bool IsDate(object pDate)
{
DateTime mDate;
if ((pDate != null) && (pDate.ToString().Trim() != ""))
{
return DateTime.TryParse(pDate.ToString(), out mDate);
}
else
{
return false;
}
}