Phương thức UInt32.ToString() trong C# được dùng để chuyển đổi giá trị số của thể hiện UInt32 hiện tại thành biểu diễn chuỗi tương đương.
Cú pháp
Cú pháp như sau:
public override string ToString();
Ví dụ 1 - Chuyển đổi 100 và 80
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");
}
}
Kết quả
Value1 (String representation) = 100 Value2 (String representation) = 80 Return value (comparison) = False val1 != val2
Ví dụ 2 - Chuyển đổi 0 và MaxValue
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");
}
}
Kết quả
Value1 (String representation) = 0 Value2 (String representation) = 4294967295 Return value (comparison) = False val1 != val2