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

เมธอด UInt64.GetTypeCode() ใน C# พร้อมตัวอย่าง

เมธอด UInt64.GetTypeCode() ใน C# ใช้คืนค่า TypeCode สำหรับประเภทค่า UInt64

ไวยากรณ์

public TypeCode GetTypeCode ();

ตัวอย่าง

ตัวอย่างที่ 1: ดึง TypeCode ของค่า ulong

using System; 
public class Demo { 
    public static void Main(){ 
        ulong val1 = 55; 
        ulong val2 = 100; 
        TypeCode type1 = val1.GetTypeCode(); 
        TypeCode type2 = val2.GetTypeCode(); 
        Console.WriteLine("Typecode for val1 = " + type1); 
        Console.WriteLine("Typecode for val2 = " + type2); 
    } 
}

ผลลัพธ์

Typecode for val1 = UInt64 
Typecode for val2 = UInt64

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

ตัวอย่างที่ 2: มีข้อผิดพลาดในโค้ดต้นฉบับ (ใช้ UInt32.MinValue แทน UInt64.MinValue) - นี่คือเวอร์ชันที่แก้ไขแล้ว

using System; 
public class Demo { 
    public static void Main(){ 
        ulong val1 = UInt64.MinValue; 
        ulong val2 = 0; 
        TypeCode type1 = val1.GetTypeCode(); 
        TypeCode type2 = val2.GetTypeCode(); 
        Console.WriteLine("Typecode for val1 = " + type1); 
        Console.WriteLine("Typecode for val2 = " + type2); 
    } 
}

ผลลัพธ์

Typecode for val1 = UInt64 
Typecode for val2 = UInt64