📜  C#| Int 64结构

📅  最后修改于: 2021-05-29 13:41:56             🧑  作者: Mango

在C#中,Int64结构用于表示从-9,223,372,036,854,775,808到+9,223,372,036,854,775,807范围的64位带符号整数(也称为long数据类型)。它提供了不同类型的方法来执行各种操作。用户可以对Int64类型执行数学操作,如加,减,乘等。它支持AND,OR,XOR等按位运算。它完全支持标准和自定义数字格式字符串。用户还可以调用Convert和Math类的方法以对Int64值执行操作。 Int64结构继承了ValueType类,后者继承了Object类。

领域

Fields Description
MaxValue This field is used to represent the largest possible value of an Int64. This field is constant.
MinValue This field is used to represent the smallest possible value of an Int64. This field is constant.

范例1:

// C# program to illustrate the 
// MaxValue and MinValue field
using System;
  
class GFG {
  
    // Main method
    static public void Main()
    {
        Int64 var1 = 89;
        Int64 var2 = 50;
        Int64 var3 = 10;
  
        // Get the Maximum and Minimum value of 
        // Int64 type Using MaxValue and 
        // MinValue field
        Console.WriteLine("Value 1: {0}", var1);
        Console.WriteLine("Value 2: {0}", var2);
        Console.WriteLine("Value 3: {0}", var3);
  
        Console.WriteLine("Maximum Value: {0}",
                               Int64.MaxValue);
  
        Console.WriteLine("Minimum Value: {0}",
                               Int64.MinValue);
    }
}
输出:
Value 1: 89
Value 2: 50
Value 3: 10
Maximum Value: 9223372036854775807
Minimum Value: -9223372036854775808

方法

Method Description
CompareTo() This method is used to compare this instance to a specified object or Int64 and returns an indication of their relative values.
Equals() This method is used to return a value indicating whether this instance is equal to a specified object or Int64.
GetHashCode() This method is used to return the hash code for this instance.
GetTypeCode() This method is used to return the TypeCode for value type Int64.
Parse() This method is used to convert the string representation of a number to its 64-bit signed integer equivalent.
ToString() This method is used to convert the numeric value of this instance to its equivalent string representation.
TryParse() This method is used to convert the string representation of a number to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.

范例1:

// C# program to demonstrate the 
// Int64.Equals(Int64) Method 
using System; 
using System.Globalization; 
    
class GFG { 
    
    // Main Method 
    public static void Main() 
    { 
        // Declaring and initializing value1 
        long value1 = 45643212342; 
    
        // Declaring and initializing value2 
        long value2 = 543256344233; 
    
        // using Equals(Int64) method 
        bool status = value1.Equals(value2); 
    
        // checking the status 
        if (status) 
            Console.WriteLine("{0} is equal to {1}", 
                                    value1, value2); 
        else
            Console.WriteLine("{0} is not equal to {1}", 
                                        value1, value2); 
    } 
} 
输出:
45643212342 is not equal to 543256344233

范例2:

// C# program to illustrate the 
// Int64.GetTypeCode() Method 
using System; 
    
class GFG { 
    
    // Main Method 
    public static void Main() 
    { 
    
        // Taking long value 
        // i.e. Int64 
        long val = 45789478123; 
    
        // Getting the typecode for Int64 
        // using GetTypeCode() method 
        TypeCode result = val.GetTypeCode(); 
    
        // Display the TypeCode  
        Console.WriteLine("TypeCode for Int64 is: {0}", 
                                               result); 
    } 
} 
输出:
TypeCode for Int64 is: Int64

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.int64?view=netframework-4.7.2