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

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

เมธอด UInt32.ToString() ใน C# ใช้สำหรับแปลงค่าตัวเลขของอินสแตนซ์ UInt32 ปัจจุบันเป็นการแทนค่าสตริงเทียบเท่า

ไวยากรณ์

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

public override string ToString();

ตัวอย่าง

ตัวอย่างการใช้งานเมธอด UInt32.ToString():

using System; 
public class Demo { 
    public static void Main(){ 
        uint val1 = 100; 
        uint val2 = 80; 
        Console.WriteLine("Value1 (String representation) = " + val1.ToString()); 
        Console.WriteLine("Value2 (String representation) = " + val2.ToString()); 
        bool res = val1.Equals(val2); 
        Console.WriteLine("Return value (comparison) = " + res); 
        if (res) 
            Console.WriteLine("val1 = val2"); 
        else 
            Console.WriteLine("val1 != val2"); 
    } 
}

ผลลัพธ์

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

Value1 (String representation) = 100 
Value2 (String representation) = 80 
Return value (comparison) = False 
val1 != val2

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

ตัวอย่างกับค่าสูงสุด:

using System; 
public class Demo { 
    public static void Main(){ 
        uint val1 = 0; 
        uint val2 = UInt32.MaxValue; 
        Console.WriteLine("Value1 (String representation) = " + val1.ToString()); 
        Console.WriteLine("Value2 (String representation) = " + val2.ToString()); 
        bool res = val1.Equals(val2); 
        Console.WriteLine("Return value (comparison) = " + res); 
        if (res) 
            Console.WriteLine("val1 = val2"); 
        else 
            Console.WriteLine("val1 != val2"); 
    } 
}

ผลลัพธ์

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

Value1 (String representation) = 0 
Value2 (String representation) = 4294967295 
Return value (comparison) = False 
val1 != val2