UInt16.ToString 方法在 C# 中的示例
C# 中的 UInt16.ToString() 方法用於將當前 UInt16 例項的數字值轉換為其等效的字串表示形式。
語法
以下為語法 −
public override string ToString();
示例
讓我們看一個實現 UInt16.ToString() 方法的示例 −
using System; public class Demo { public static void Main(){ ushort val1 = 100; ushort 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
示例
讓我們看另一個實現 UInt16.ToString() 方法的示例 −
using System; public class Demo { public static void Main(){ ushort val1 = 0; ushort val2 = UInt16.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) = 65535 Return value (comparison) = False val1 != val2
廣告