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
相關用法
- C# UInt16.ToString()方法用法及代碼示例
- C# UInt16.MaxValue用法及代碼示例
- C# UInt16.Equals用法及代碼示例
- C# UInt16.GetTypeCode用法及代碼示例
- C# UInt16.GetTypeCode()用法及代碼示例
- C# UInt16.GetHashCode()用法及代碼示例
- C# UInt16.Parse(String)用法及代碼示例
- C# UInt16.CompareTo()用法及代碼示例
- C# UInt16.GetHashCode用法及代碼示例
- C# UInt16.MinValue用法及代碼示例
- C# UInt64.ToString()用法及代碼示例
- C# UInt64.Equals用法及代碼示例
- C# UInt32.GetHashCode()用法及代碼示例
- C# UInt64.GetHashCode用法及代碼示例
- C# UInt64.MinValue用法及代碼示例
- C# UInt64.GetTypeCode()用法及代碼示例
- C# UInt32.CompareTo()用法及代碼示例
- C# UInt32.MinValue用法及代碼示例
- C# UInt32.ToString()用法及代碼示例
- C# UInt32.MaxValue用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 UInt16.ToString Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。