DateTime.GetTypeCode() Method in C#


he DateTime.GetTypeCode() method in C# is used to return the TypeCode for value type DateTime. The returned value is the enumerated constant, DateTime.

Syntax

Following is the syntax −

public TypeCode GetTypeCode ();

Example

Let us now see an example to implement the DateTime.GetTypeCode() method −

using System;
public class Demo {
   public static void Main() {
      DateTime d = DateTime.Now;
      TypeCode res = d.GetTypeCode();
      Console.WriteLine("TypeCode of Date {0} = {1} ", d, res);
   }
}

Output

This will produce the following output −

TypeCode of Date 10/16/2019 7:08:50 AM = DateTime

Example

Let us now see another example to implement the DateTime.GetTypeCode() method −

using System;
public class Demo {
   public static void Main() {
      DateTime d = new DateTime(2019, 10, 11, 7, 10, 40);
      TypeCode res = d.GetTypeCode();
      Console.WriteLine("TypeCode of Date {0} = {1} ", d, res);
   }
}

Output

This will produce the following output −

TypeCode of Date 10/11/2019 7:10:40 AM = DateTime
raja
Published on 08-Nov-2019 10:36:59
Advertisements