Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

เมธอด DateTime.GetTypeCode() ใน C#

เมธอด DateTime.GetTypeCode() ใน C# ใช้สำหรับคืนค่า TypeCode สำหรับประเภทค่า DateTime ค่าที่คืนกลับคือค่าคงที่แอนัมเรท (enumerated constant) คือ DateTime

ไวยากรณ์

ไวยากรณ์มีดังนี้:

public TypeCode GetTypeCode ();

ตัวอย่าง

ตัวอย่างการใช้งานเมธอด DateTime.GetTypeCode() กับ DateTime.Now:

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); 
    } 
}

ผลลัพธ์

โค้ดจะแสดงผลดังนี้ (ตัวอย่าง):

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

ตัวอย่างเพิ่มเติม

ตัวอย่างที่สองกับวันที่เฉพาะเจาะจง:

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); 
    } 
}

ผลลัพธ์

โค้ดจะแสดงผลดังนี้:

TypeCode of Date 10/11/2019 7:10:40 AM = DateTime