C# 中的 SByte.ToString() 方法用於將此實例的數值轉換為其等效的字符串表示形式。
用法
語法如下 -
public override string ToString ();
示例
現在讓我們看一個例子 -
using System;
public class Demo {
public static void Main(){
sbyte s1 = 10;
sbyte s2 = 100;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
int res = s1.CompareTo(s2);
if (res > 0)
Console.WriteLine("s1 > s2");
else if (res < 0)
Console.WriteLine("s1 < s2");
else
Console.WriteLine("s1 = s2");
Console.WriteLine("\nHashCode for s1 = "+s1.GetHashCode());
Console.WriteLine("GetTypeCode for s1 = "+s1.GetTypeCode());
Console.WriteLine("String representation for s1 = "+s1.ToString());
Console.WriteLine("\nHashCode for s2 = "+s2.GetHashCode());
Console.WriteLine("GetTypeCode for s2 = "+s2.GetTypeCode());
Console.WriteLine("String representation for s2 = "+s2.ToString());
}
}
輸出
這將產生以下輸出 -
Value of S1 = 10 Value of S2 = 100 s1 − s2 HashCode for s1 = 2570 GetTypeCode for s1 = SByte String representation for s1 = 10 HashCode for s2 = 25700 GetTypeCode for s2 = SByte String representation for s2 = 100
示例
現在讓我們看另一個例子 -
using System;
public class Demo {
public static void Main(){
sbyte s1 = 99;
sbyte s2 = SByte.MaxValue;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
Console.WriteLine("Is s1 and s2 equal? = "+s1.Equals(s2));
int res = s1.CompareTo(s2);
if (res > 0)
Console.WriteLine("s1 > s2");
else if (res < 0)
Console.WriteLine("s1 < s2");
else
Console.WriteLine("s1 = s2");
Console.WriteLine("String representation for s1 = "+s1.ToString());
Console.WriteLine("String representation for s2 = "+s2.ToString());
}
}
輸出
這將產生以下輸出 -
Value of S1 = 99 Value of S2 = 127 Is s1 and s2 equal? = False s1 < s2 String representation for s1 = 99 String representation for s2 = 127
相關用法
- C# SByte.ToString()方法用法及代碼示例
- C# SByte.Equals用法及代碼示例
- C# SByte.Equals()用法及代碼示例
- C# SByte.GetHashCode()用法及代碼示例
- C# SByte.GetHashCode用法及代碼示例
- C# SByte.CompareTo()用法及代碼示例
- C# SByte.GetTypeCode用法及代碼示例
- C# String.ToUpperInvariant用法及代碼示例
- C# StringBuilder.ToString用法及代碼示例
- C# Stack.Contains()用法及代碼示例
- C# String ToString()用法及代碼示例
- C# String Contains()用法及代碼示例
- C# String ToCharArray()用法及代碼示例
- C# SortedDictionary.Remove()用法及代碼示例
- C# String IndexOf()用法及代碼示例
- C# String TrimEnd()用法及代碼示例
- C# String Concat()用法及代碼示例
- C# Single.IsNegative()用法及代碼示例
- C# String IsNormalized()用法及代碼示例
- C# SortedDictionary.Item[]用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 SByte.ToString() Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。