Verifies if the object is a date - CSharp System

CSharp examples for System:DateTime Calculate

Description

Verifies if the object is a date

Demo Code

//   The contents of this file are subject to the New BSD
using System;//w  w w  . j  av  a  2s. c  o  m

public class Main{
        /// <summary>
    /// Verifies if the object is a date
    /// </summary>
    /// <param name="dt">The dt.</param>
    /// <returns>
    /// 	<c>true</c> if the specified dt is date; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsDate(this object dt) {
        DateTime newDate;
        return DateTime.TryParse(dt.ToString(), out newDate);
    }
}

Related Tutorials