C# 中的 Int64.ToString() 方法用於將此實例的數值轉換為其等效的字符串表示形式。
用法
語法如下 -
public override string ToString (); public string ToString (string format);
上麵,參數格式是一個數字格式字符串。
示例
現在讓我們看一個例子 -
using System;
public class Demo {
public static void Main(){
long val1 = 0;
long val2 = Int64.MaxValue;
Console.WriteLine("Value1 = "+val1.ToString());
Console.WriteLine("Value2 = "+val2.ToString());
Console.WriteLine("Are they equal? = "+val1.Equals(val2));
Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode());
Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode());
TypeCode type1 = val1.GetTypeCode();
TypeCode type2 = val2.GetTypeCode();
Console.WriteLine("TypeCode for val1 = "+val1.GetTypeCode());
Console.WriteLine("TypeCode for val2 = = "+val1.GetTypeCode());
}
}
輸出
這將產生以下輸出 -
Value1 = 0 Value2 = 9223372036854775807 Are they equal? = False Value1 (HashCode) = 0 Value2 (HashCode) = -2147483648 TypeCode for val1 = Int64 TypeCode for val2 = = Int64
示例
現在讓我們看另一個例子 -
using System;
public class Demo {
public static void Main(){
long val1 = 87987687;
long val2 = 35436367;
Console.WriteLine("Value1 = "+val1.ToString("D8"));
Console.WriteLine("Value2 = "+val2.ToString("X"));
Console.WriteLine("Are they equal? = "+val1.Equals(val2));
Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode());
Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode());
TypeCode type1 = val1.GetTypeCode();
TypeCode type2 = val2.GetTypeCode();
Console.WriteLine("TypeCode for val1 = "+val1.GetTypeCode());
Console.WriteLine("TypeCode for val2 = = "+val1.GetTypeCode());
}
}
輸出
這將產生以下輸出 -
Value1 = 87987687 Value2 = 21CB74F Are they equal? = False Value1 (HashCode) = 87987687 Value2 (HashCode) = 35436367 TypeCode for val1 = Int64 TypeCode for val2 = = Int64
相關用法
- C# Int64.Equals用法及代碼示例
- C# Int64.Parse(String)用法及代碼示例
- C# Int64.GetHashCode用法及代碼示例
- C# Int64.GetTypeCode用法及代碼示例
- C# Int64.CompareTo用法及代碼示例
- C# Int64.MinValue用法及代碼示例
- C# Int64.MaxValue用法及代碼示例
- C# Int32.CompareTo用法及代碼示例
- C# Int32.GetHashCode用法及代碼示例
- C# Int32.Parse(String)用法及代碼示例
- C# Int16.ToString()用法及代碼示例
- C# Int16.MaxValue用法及代碼示例
- C# Int32.GetTypeCode用法及代碼示例
- C# Int16.MinValue用法及代碼示例
- C# Int16.Parse(String)用法及代碼示例
- C# Int32.MinValue用法及代碼示例
- C# Int32.MaxValue用法及代碼示例
- C# Int16.GetHashCode用法及代碼示例
- C# Int16.CompareTo()用法及代碼示例
- C# Int16.GetHashCode()用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 Int64.ToString() Method in C#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。