Int64 結構

定義

表示 64 位元帶正負號的整數。

public value class long : IComparable, IComparable<long>, IConvertible, IEquatable<long>, IFormattable
public value class long : IComparable, IComparable<long>, IConvertible, IEquatable<long>, ISpanFormattable
public value class long : IComparable<long>, IConvertible, IEquatable<long>, IParsable<long>, ISpanParsable<long>, System::Numerics::IAdditionOperators<long, long, long>, System::Numerics::IAdditiveIdentity<long, long>, System::Numerics::IBinaryInteger<long>, System::Numerics::IBinaryNumber<long>, System::Numerics::IBitwiseOperators<long, long, long>, System::Numerics::IComparisonOperators<long, long, bool>, System::Numerics::IDecrementOperators<long>, System::Numerics::IDivisionOperators<long, long, long>, System::Numerics::IEqualityOperators<long, long, bool>, System::Numerics::IIncrementOperators<long>, System::Numerics::IMinMaxValue<long>, System::Numerics::IModulusOperators<long, long, long>, System::Numerics::IMultiplicativeIdentity<long, long>, System::Numerics::IMultiplyOperators<long, long, long>, System::Numerics::INumber<long>, System::Numerics::INumberBase<long>, System::Numerics::IShiftOperators<long, int, long>, System::Numerics::ISignedNumber<long>, System::Numerics::ISubtractionOperators<long, long, long>, System::Numerics::IUnaryNegationOperators<long, long>, System::Numerics::IUnaryPlusOperators<long, long>
public value class long : IComparable<long>, IConvertible, IEquatable<long>, IParsable<long>, ISpanParsable<long>, IUtf8SpanParsable<long>, System::Numerics::IAdditionOperators<long, long, long>, System::Numerics::IAdditiveIdentity<long, long>, System::Numerics::IBinaryInteger<long>, System::Numerics::IBinaryNumber<long>, System::Numerics::IBitwiseOperators<long, long, long>, System::Numerics::IComparisonOperators<long, long, bool>, System::Numerics::IDecrementOperators<long>, System::Numerics::IDivisionOperators<long, long, long>, System::Numerics::IEqualityOperators<long, long, bool>, System::Numerics::IIncrementOperators<long>, System::Numerics::IMinMaxValue<long>, System::Numerics::IModulusOperators<long, long, long>, System::Numerics::IMultiplicativeIdentity<long, long>, System::Numerics::IMultiplyOperators<long, long, long>, System::Numerics::INumber<long>, System::Numerics::INumberBase<long>, System::Numerics::IShiftOperators<long, int, long>, System::Numerics::ISignedNumber<long>, System::Numerics::ISubtractionOperators<long, long, long>, System::Numerics::IUnaryNegationOperators<long, long>, System::Numerics::IUnaryPlusOperators<long, long>
public value class long : IComparable, IConvertible, IFormattable
public value class long : IComparable, IComparable<long>, IEquatable<long>, IFormattable
public struct Int64 : IComparable, IComparable<long>, IConvertible, IEquatable<long>, IFormattable
public readonly struct Int64 : IComparable, IComparable<long>, IConvertible, IEquatable<long>, IFormattable
public readonly struct Int64 : IComparable, IComparable<long>, IConvertible, IEquatable<long>, ISpanFormattable
public readonly struct Int64 : IComparable<long>, IConvertible, IEquatable<long>, IParsable<long>, ISpanParsable<long>, System.Numerics.IAdditionOperators<long,long,long>, System.Numerics.IAdditiveIdentity<long,long>, System.Numerics.IBinaryInteger<long>, System.Numerics.IBinaryNumber<long>, System.Numerics.IBitwiseOperators<long,long,long>, System.Numerics.IComparisonOperators<long,long,bool>, System.Numerics.IDecrementOperators<long>, System.Numerics.IDivisionOperators<long,long,long>, System.Numerics.IEqualityOperators<long,long,bool>, System.Numerics.IIncrementOperators<long>, System.Numerics.IMinMaxValue<long>, System.Numerics.IModulusOperators<long,long,long>, System.Numerics.IMultiplicativeIdentity<long,long>, System.Numerics.IMultiplyOperators<long,long,long>, System.Numerics.INumber<long>, System.Numerics.INumberBase<long>, System.Numerics.IShiftOperators<long,int,long>, System.Numerics.ISignedNumber<long>, System.Numerics.ISubtractionOperators<long,long,long>, System.Numerics.IUnaryNegationOperators<long,long>, System.Numerics.IUnaryPlusOperators<long,long>
public readonly struct Int64 : IComparable<long>, IConvertible, IEquatable<long>, IParsable<long>, ISpanParsable<long>, IUtf8SpanParsable<long>, System.Numerics.IAdditionOperators<long,long,long>, System.Numerics.IAdditiveIdentity<long,long>, System.Numerics.IBinaryInteger<long>, System.Numerics.IBinaryNumber<long>, System.Numerics.IBitwiseOperators<long,long,long>, System.Numerics.IComparisonOperators<long,long,bool>, System.Numerics.IDecrementOperators<long>, System.Numerics.IDivisionOperators<long,long,long>, System.Numerics.IEqualityOperators<long,long,bool>, System.Numerics.IIncrementOperators<long>, System.Numerics.IMinMaxValue<long>, System.Numerics.IModulusOperators<long,long,long>, System.Numerics.IMultiplicativeIdentity<long,long>, System.Numerics.IMultiplyOperators<long,long,long>, System.Numerics.INumber<long>, System.Numerics.INumberBase<long>, System.Numerics.IShiftOperators<long,int,long>, System.Numerics.ISignedNumber<long>, System.Numerics.ISubtractionOperators<long,long,long>, System.Numerics.IUnaryNegationOperators<long,long>, System.Numerics.IUnaryPlusOperators<long,long>
[System.Serializable]
public struct Int64 : IComparable, IConvertible, IFormattable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct Int64 : IComparable, IComparable<long>, IConvertible, IEquatable<long>, IFormattable
public struct Int64 : IComparable, IComparable<long>, IEquatable<long>, IFormattable
type int64 = struct
    interface IConvertible
    interface IFormattable
type int64 = struct
    interface IConvertible
    interface ISpanFormattable
    interface IFormattable
type int64 = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<int64>
    interface ISpanFormattable
    interface ISpanParsable<int64>
    interface IAdditionOperators<int64, int64, int64>
    interface IAdditiveIdentity<int64, int64>
    interface IBinaryInteger<int64>
    interface IBinaryNumber<int64>
    interface IBitwiseOperators<int64, int64, int64>
    interface IComparisonOperators<int64, int64, bool>
    interface IEqualityOperators<int64, int64, bool>
    interface IDecrementOperators<int64>
    interface IDivisionOperators<int64, int64, int64>
    interface IIncrementOperators<int64>
    interface IModulusOperators<int64, int64, int64>
    interface IMultiplicativeIdentity<int64, int64>
    interface IMultiplyOperators<int64, int64, int64>
    interface INumber<int64>
    interface INumberBase<int64>
    interface ISubtractionOperators<int64, int64, int64>
    interface IUnaryNegationOperators<int64, int64>
    interface IUnaryPlusOperators<int64, int64>
    interface IShiftOperators<int64, int, int64>
    interface IMinMaxValue<int64>
    interface ISignedNumber<int64>
type int64 = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<int64>
    interface ISpanFormattable
    interface ISpanParsable<int64>
    interface IAdditionOperators<int64, int64, int64>
    interface IAdditiveIdentity<int64, int64>
    interface IBinaryInteger<int64>
    interface IBinaryNumber<int64>
    interface IBitwiseOperators<int64, int64, int64>
    interface IComparisonOperators<int64, int64, bool>
    interface IEqualityOperators<int64, int64, bool>
    interface IDecrementOperators<int64>
    interface IDivisionOperators<int64, int64, int64>
    interface IIncrementOperators<int64>
    interface IModulusOperators<int64, int64, int64>
    interface IMultiplicativeIdentity<int64, int64>
    interface IMultiplyOperators<int64, int64, int64>
    interface INumber<int64>
    interface INumberBase<int64>
    interface ISubtractionOperators<int64, int64, int64>
    interface IUnaryNegationOperators<int64, int64>
    interface IUnaryPlusOperators<int64, int64>
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<int64>
    interface IShiftOperators<int64, int, int64>
    interface IMinMaxValue<int64>
    interface ISignedNumber<int64>
[<System.Serializable>]
type int64 = struct
    interface IFormattable
    interface IConvertible
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type int64 = struct
    interface IFormattable
    interface IConvertible
type int64 = struct
    interface IFormattable
Public Structure Int64
Implements IComparable, IComparable(Of Long), IConvertible, IEquatable(Of Long), IFormattable
Public Structure Int64
Implements IComparable, IComparable(Of Long), IConvertible, IEquatable(Of Long), ISpanFormattable
Public Structure Int64
Implements IAdditionOperators(Of Long, Long, Long), IAdditiveIdentity(Of Long, Long), IBinaryInteger(Of Long), IBinaryNumber(Of Long), IBitwiseOperators(Of Long, Long, Long), IComparable(Of Long), IComparisonOperators(Of Long, Long, Boolean), IConvertible, IDecrementOperators(Of Long), IDivisionOperators(Of Long, Long, Long), IEqualityOperators(Of Long, Long, Boolean), IEquatable(Of Long), IIncrementOperators(Of Long), IMinMaxValue(Of Long), IModulusOperators(Of Long, Long, Long), IMultiplicativeIdentity(Of Long, Long), IMultiplyOperators(Of Long, Long, Long), INumber(Of Long), INumberBase(Of Long), IParsable(Of Long), IShiftOperators(Of Long, Integer, Long), ISignedNumber(Of Long), ISpanParsable(Of Long), ISubtractionOperators(Of Long, Long, Long), IUnaryNegationOperators(Of Long, Long), IUnaryPlusOperators(Of Long, Long)
Public Structure Int64
Implements IAdditionOperators(Of Long, Long, Long), IAdditiveIdentity(Of Long, Long), IBinaryInteger(Of Long), IBinaryNumber(Of Long), IBitwiseOperators(Of Long, Long, Long), IComparable(Of Long), IComparisonOperators(Of Long, Long, Boolean), IConvertible, IDecrementOperators(Of Long), IDivisionOperators(Of Long, Long, Long), IEqualityOperators(Of Long, Long, Boolean), IEquatable(Of Long), IIncrementOperators(Of Long), IMinMaxValue(Of Long), IModulusOperators(Of Long, Long, Long), IMultiplicativeIdentity(Of Long, Long), IMultiplyOperators(Of Long, Long, Long), INumber(Of Long), INumberBase(Of Long), IParsable(Of Long), IShiftOperators(Of Long, Integer, Long), ISignedNumber(Of Long), ISpanParsable(Of Long), ISubtractionOperators(Of Long, Long, Long), IUnaryNegationOperators(Of Long, Long), IUnaryPlusOperators(Of Long, Long), IUtf8SpanParsable(Of Long)
Public Structure Int64
Implements IComparable, IConvertible, IFormattable
Public Structure Int64
Implements IComparable, IComparable(Of Long), IEquatable(Of Long), IFormattable
繼承
屬性
實作
IComparable IComparable<Int64> IConvertible IEquatable<Int64> IFormattable ISpanFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<Int64> IParsable<TSelf> ISpanParsable<Int64> ISpanParsable<TSelf> IAdditionOperators<Int64,Int64,Int64> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<Int64,Int64> IAdditiveIdentity<TSelf,TSelf> IBinaryInteger<Int64> IBinaryNumber<Int64> IBinaryNumber<TSelf> IBitwiseOperators<Int64,Int64,Int64> IBitwiseOperators<TSelf,TSelf,TSelf> IComparisonOperators<Int64,Int64,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<Int64> IDecrementOperators<TSelf> IDivisionOperators<Int64,Int64,Int64> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<Int64,Int64,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IIncrementOperators<Int64> IIncrementOperators<TSelf> IMinMaxValue<Int64> IModulusOperators<Int64,Int64,Int64> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<Int64,Int64> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<Int64,Int64,Int64> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<Int64> INumber<TSelf> INumberBase<Int64> INumberBase<TSelf> IShiftOperators<Int64,Int32,Int64> IShiftOperators<TSelf,Int32,TSelf> ISignedNumber<Int64> ISubtractionOperators<Int64,Int64,Int64> ISubtractionOperators<TSelf,TSelf,TSelf> IUnaryNegationOperators<Int64,Int64> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<Int64,Int64> IUnaryPlusOperators<TSelf,TSelf> IUtf8SpanFormattable IUtf8SpanParsable<Int64> IUtf8SpanParsable<TSelf>

備註

Int64 是不可變的實值型別,代表具有負數 9,223,372,036,854,775,808 (值的帶正負號整數 會以 Int64.MinValue 常數) 表示至正 9,223,372,036,854,775,807 (,由常數表示 Int64.MaxValue 。 .NET Framework也包含不帶正負號的 64 位整數實數值型別, UInt64 代表範圍從 0 到 18,446,744,073,709,551,615 的值。

具現化 Int64 值

您可以透過數種方式具現化 Int64 值:

  • 您可以宣告 Int64 變數,並為其指派資料類型範圍內 Int64 常值整數值。 下列範例會宣告兩 Int64 個變數,並以這種方式指派這些變數。

    long number1 = -64301728;
    long number2 = 255486129307;
    
    let number1 = -64301728L
    let number2 = 255486129307L
    
    Dim number1 As Long = -64301728
    Dim number2 As Long = 255486129307
    
  • 您可以指派整數型別的值,其範圍是型別的 Int64 子集。 這是擴輾轉換,不需要 C# 中的轉換運算子或 Visual Basic 中的轉換方法。 在 F# 中 Int32 ,只能自動擴大類型。

    sbyte value1 = 124;
    short value2 = 1618;
    int value3 = Int32.MaxValue;
    
    long number1 = value1;
    long number2 = value2;
    long number3 = value3;
    
    let value1 = 124y
    let value2 = 1618s
    let value3 = Int32.MaxValue
    
    let number1 = int64 value1
    let number2 = int64 value2
    let number3: int64 = value3
    
    Dim value1 As SByte = 124
    Dim value2 As Int16 = 1618
    Dim value3 As Int32 = Int32.MaxValue
    
    Dim number1 As Long = value1
    Dim number2 As Long = value2
    Dim number3 As Long = value3
    
  • 您可以指派數數值型別的值,其範圍超過 Int64 該類型的值。 這是縮小轉換,因此如果 開啟,則需要 C# 或 F# 中的轉換運算子和 Visual Basic Option Strict 中的轉換方法。 如果數值是包含 Single 小陣列件的 、 DoubleDecimal 值,則其小數部分的處理取決於執行轉換的編譯器。 下列範例會執行縮小轉換,將數個數值指派給 Int64 變數。

    ulong ulNumber = 163245617943825;
    try {
       long number1 = (long) ulNumber;
       Console.WriteLine(number1);
    }
    catch (OverflowException) {
       Console.WriteLine("{0} is out of range of an Int64.", ulNumber);
    }
    
    double dbl2 = 35901.997;
    try {
       long number2 = (long) dbl2;
       Console.WriteLine(number2);
    }
    catch (OverflowException) {
       Console.WriteLine("{0} is out of range of an Int64.", dbl2);
    }
    
    BigInteger bigNumber = (BigInteger) 1.63201978555e30;
    try {
       long number3 = (long) bigNumber;
       Console.WriteLine(number3);
    }
    catch (OverflowException) {
       Console.WriteLine("{0} is out of range of an Int64.", bigNumber);
    }
    // The example displays the following output:
    //    163245617943825
    //    35902
    //    1,632,019,785,549,999,969,612,091,883,520 is out of range of an Int64.
    
    let ulNumber = 163245617943825uL
    try
        let number1 = int64 ulNumber
        printfn $"{number1}"
    with :? OverflowException ->
        printfn $"{ulNumber} is out of range of an Int64."
    
    let dbl2 = 35901.997
    try
        let number2 = int64 dbl2
        printfn $"{number2}"
    with :? OverflowException ->
        printfn $"{dbl2} is out of range of an Int64."
    
    let bigNumber = BigInteger 1.63201978555e30
    try
        let number3 = int64 bigNumber
        printfn $"{number3}"
    with :? OverflowException ->
        printfn $"{bigNumber} is out of range of an Int64."
    
    // The example displays the following output:
    //    163245617943825
    //    35902
    //    1,632,019,785,549,999,969,612,091,883,520 is out of range of an Int64.
    
    Dim ulNumber As ULong = 163245617943825
    Try
       Dim number1 As Long = CLng(ulNumber)
       Console.WriteLine(number1)
    Catch e As OverflowException
       Console.WriteLine("{0} is out of range of an Int64.", ulNumber)
    End Try
    
    Dim dbl2 As Double = 35901.997
    Try
       Dim number2 As Long = CLng(dbl2)
       Console.WriteLine(number2)
    Catch e As OverflowException
       Console.WriteLine("{0} is out of range of an Int64.", dbl2)
    End Try
       
    Dim bigNumber As BigInteger = 1.63201978555e30
    Try
       Dim number3 As Long = CLng(bigNumber)
       Console.WriteLine(number3)
    Catch e As OverflowException
       Console.WriteLine("{0:N0} is out of range of an Int64.", bigNumber)
    End Try    
    ' The example displays the following output:
    '    163245617943825
    '    35902
    '    1,632,019,785,549,999,969,612,091,883,520 is out of range of an Int64.
    
  • 您可以呼叫 類別的方法, Convert 將任何支援的型別 Int64 轉換為值。 這是可行的,因為 Int64 支援 IConvertible 介面。 下列範例說明將值 Int64 陣列 Decimal 轉換成值。

    decimal[] values= { Decimal.MinValue, -1034.23m, -12m, 0m, 147m,
                        199.55m, 9214.16m, Decimal.MaxValue };
    long result;
    
    foreach (decimal value in values)
    {
       try {
          result = Convert.ToInt64(value);
          Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                            value.GetType().Name, value,
                            result.GetType().Name, result);
       }
       catch (OverflowException) {
          Console.WriteLine("{0} is outside the range of the Int64 type.",
                            value);
       }
    }
    // The example displays the following output:
    //    -79228162514264337593543950335 is outside the range of the Int64 type.
    //    Converted the Decimal value '-1034.23' to the Int64 value -1034.
    //    Converted the Decimal value '-12' to the Int64 value -12.
    //    Converted the Decimal value '0' to the Int64 value 0.
    //    Converted the Decimal value '147' to the Int64 value 147.
    //    Converted the Decimal value '199.55' to the Int64 value 200.
    //    Converted the Decimal value '9214.16' to the Int64 value 9214.
    //    79228162514264337593543950335 is outside the range of the Int64 type.
    
    let values= 
        [| Decimal.MinValue; -1034.23M; -12M; 0M; 147M
           199.55M; 9214.16M; Decimal.MaxValue |]
    
    for value in values do
        try
            let result = Convert.ToInt64 value
            printfn $"Converted the {value.GetType().Name} value '{value}' to the {result.GetType().Name} value {result}." 
        with :? OverflowException ->
            printfn $"{value} is outside the range of the Int64 type."
        
    // The example displays the following output:
    //    -79228162514264337593543950335 is outside the range of the Int64 type.
    //    Converted the Decimal value '-1034.23' to the Int64 value -1034.
    //    Converted the Decimal value '-12' to the Int64 value -12.
    //    Converted the Decimal value '0' to the Int64 value 0.
    //    Converted the Decimal value '147' to the Int64 value 147.
    //    Converted the Decimal value '199.55' to the Int64 value 200.
    //    Converted the Decimal value '9214.16' to the Int64 value 9214.
    //    79228162514264337593543950335 is outside the range of the Int64 type.
    
    Dim values() As Decimal = { Decimal.MinValue, -1034.23d, -12d, 0d, 147d, _
                                199.55d, 9214.16d, Decimal.MaxValue }
    Dim result As Long
    
    For Each value As Decimal In values
       Try
          result = Convert.ToInt64(value)
          Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.", _
                            value.GetType().Name, value, _
                            result.GetType().Name, result)
       Catch e As OverflowException
          Console.WriteLine("{0} is outside the range of the Int64 type.", _
                            value)
       End Try
    Next
    ' The example displays the following output:
    '    -79228162514264337593543950335 is outside the range of the Int64 type.
    '    Converted the Decimal value '-1034.23' to the Int64 value -1034.
    '    Converted the Decimal value '-12' to the Int64 value -12.
    '    Converted the Decimal value '0' to the Int64 value 0.
    '    Converted the Decimal value '147' to the Int64 value 147.
    '    Converted the Decimal value '199.55' to the Int64 value 200.
    '    Converted the Decimal value '9214.16' to the Int64 value 9214.
    '    79228162514264337593543950335 is outside the range of the Int64 type.
    
  • 您可以呼叫 ParseTryParse 方法,將值的字串表示 Int64 轉換成 Int64 。 字串可以包含十進位或十六進位數位。 下列範例說明使用十進位和十六進位字串來剖析作業。

    string string1 = "244681903147";
    try {
       long number1 = Int64.Parse(string1);
       Console.WriteLine(number1);
    }
    catch (OverflowException) {
       Console.WriteLine("'{0}' is out of range of a 64-bit integer.", string1);
    }
    catch (FormatException) {
       Console.WriteLine("The format of '{0}' is invalid.", string1);
    }
    
    string string2 = "F9A3CFF0A";
    try {
       long number2 = Int64.Parse(string2,
                                  System.Globalization.NumberStyles.HexNumber);
       Console.WriteLine(number2);
    }
    catch (OverflowException) {
       Console.WriteLine("'{0}' is out of range of a 64-bit integer.", string2);
    }
    catch (FormatException) {
       Console.WriteLine("The format of '{0}' is invalid.", string2);
    }
    // The example displays the following output:
    //    244681903147
    //    67012198154
    
    let string1 = "244681903147"
    try
        let number1 = Int64.Parse string1
        printfn $"{number1}"
    with
    | :? OverflowException ->
        printfn $"'{string1}' is out of range of a 64-bit integer."
    | :? FormatException ->
        printfn $"The format of '{string1}' is invalid."
    
    let string2 = "F9A3CFF0A"
    try
        let number2 = Int64.Parse(string2, NumberStyles.HexNumber)
        printfn $"{number2}"
    
    with
    | :? OverflowException ->
        printfn $"'{string2}' is out of range of a 64-bit integer."
    | :? FormatException ->
        printfn $"The format of '{string2}' is invalid."
    
    // The example displays the following output:
    //    244681903147
    //    67012198154
    
    Dim string1 As String = "244681903147"
    Try
       Dim number1 As Long = Int64.Parse(string1)
       Console.WriteLine(number1)
    Catch e As OverflowException
       Console.WriteLine("'{0}' is out of range of a 64-bit integer.", string1)
    Catch e As FormatException
       Console.WriteLine("The format of '{0}' is invalid.", string1)
    End Try
    
    Dim string2 As String = "F9A3CFF0A"
    Try
       Dim number2 As Long = Int64.Parse(string2,
                                System.Globalization.NumberStyles.HexNumber)
       Console.WriteLine(number2)
    Catch e As OverflowException
       Console.WriteLine("'{0}' is out of range of a 64-bit integer.", string2)
    Catch e As FormatException
       Console.WriteLine("The format of '{0}' is invalid.", string2)
    End Try
    ' The example displays the following output:
    '    244681903147
    '    67012198154
    

在 Int64 值上執行作業

Int64 類型支援標準數學運算,例如加法、減法、除法、乘法、負數和一元負數。 與其他整數類型一樣,此 Int64 類型也支援位 ANDORXOR 左移和右移運算子。

您可以使用標準數值運算子來比較兩 Int64 個值,也可以呼叫 CompareToEquals 方法。

您也可以呼叫 類別的成員 Math 來執行廣泛的數值運算,包括取得數位的絕對值、計算整數除法的商數和餘數、判斷兩個長整數的最大值或最小值、取得數位的正負號,以及四捨五入數位。

以字串表示 Int64

Int64 類型提供標準和自訂數值格式字串的完整支援。 (如需詳細資訊,請參閱 格式化類型標準數值格式字串自訂數值格式字串s.)

若要將 Int64 值格式化為不含前置零的整數位符串,您可以呼叫無 ToString() 參數方法。 藉由使用 「D」 格式規範,您也可以在字串表示中包含指定數目的前置零。 藉由使用 「N」 格式規範,您可以包含群組分隔符號,並指定要出現在數位字串表示中的十進位數數目。 藉由使用 「X」 格式規範,您可以將值表示 Int64 為十六進位字串。 下列範例會以下列四種方式格式化值陣列中的 Int64 專案。

long[] numbers = { -1403, 0, 169, 1483104 };
foreach (var number in numbers) {
   // Display value using default formatting.
   Console.Write("{0,-8}  -->   ", number.ToString());
   // Display value with 3 digits and leading zeros.
   Console.Write("{0,8:D3}", number);
   // Display value with 1 decimal digit.
   Console.Write("{0,13:N1}", number);
   // Display value as hexadecimal.
   Console.Write("{0,18:X2}", number);
   // Display value with eight hexadecimal digits.
   Console.WriteLine("{0,18:X8}", number);
}
// The example displays the following output:
//    -1403     -->      -1403     -1,403.0  FFFFFFFFFFFFFA85  FFFFFFFFFFFFFA85
//    0         -->        000          0.0                00          00000000
//    169       -->        169        169.0                A9          000000A9
//    1483104   -->    1483104  1,483,104.0            16A160          0016A160
let numbers = [| -1403L; 0L; 169L; 1483104L |]
for number in numbers do
    // Display value using default formatting.
    printf $"{number.ToString(),-8}  -->   "
    // Display value with 3 digits and leading zeros.
    printf $"{number,8:D3}"
    // Display value with 1 decimal digit.
    printf $"{number,13:N1}"
    // Display value as hexadecimal.
    printf $"{number,18:X2}"
    // Display value with eight hexadecimal digits.
    printfn $"{number,18:X8}"

// The example displays the following output:
//    -1403     -->      -1403     -1,403.0  FFFFFFFFFFFFFA85  FFFFFFFFFFFFFA85
//    0         -->        000          0.0                00          00000000
//    169       -->        169        169.0                A9          000000A9
//    1483104   -->    1483104  1,483,104.0            16A160          0016A160
Dim numbers() As Long = { -1403, 0, 169, 1483104 }
For Each number In numbers
   ' Display value using default formatting.
   Console.Write("{0,-8}  -->   ", number.ToString())
   ' Display value with 3 digits and leading zeros.
   Console.Write("{0,8:D3}", number)
   ' Display value with 1 decimal digit.
   Console.Write("{0,13:N1}", number) 
   ' Display value as hexadecimal.
   Console.Write("{0,18:X2}", number)
   ' Display value with eight hexadecimal digits.
   Console.WriteLine("{0,18:X8}", number)
Next   
' The example displays the following output:
'    -1403     -->      -1403     -1,403.0  FFFFFFFFFFFFFA85  FFFFFFFFFFFFFA85
'    0         -->        000          0.0                00          00000000
'    169       -->        169        169.0                A9          000000A9
'    1483104   -->    1483104  1,483,104.0            16A160          0016A160

您也可以呼叫 ToString(Int64, Int32) 方法,並提供基底做為方法的第二個參數,將值格式化 Int64 為二進位、八進位、十六進位或十六進位字串。 下列範例會呼叫這個方法,以顯示整數值陣列的二進位、八進位和十六進位標記法。

long[] numbers = { -146, 11043, 2781913 };
foreach (var number in numbers) {
   Console.WriteLine("{0} (Base 10):", number);
   Console.WriteLine("   Binary:  {0}", Convert.ToString(number, 2));
   Console.WriteLine("   Octal:   {0}", Convert.ToString(number, 8));
   Console.WriteLine("   Hex:     {0}\n", Convert.ToString(number, 16));
}
// The example displays the following output:
//    -146 (Base 10):
//       Binary:  1111111111111111111111111111111111111111111111111111111101101110
//       Octal:   1777777777777777777556
//       Hex:     ffffffffffffff6e
//
//    11043 (Base 10):
//       Binary:  10101100100011
//       Octal:   25443
//       Hex:     2b23
//
//    2781913 (Base 10):
//       Binary:  1010100111001011011001
//       Octal:   12471331
//       Hex:     2a72d9
let numbers = [| -146L; 11043L; 2781913L |]
for number in numbers do
    printfn $"{number} (Base 10):"
    printfn $"   Binary:  {Convert.ToString(number, 2)}"
    printfn $"   Octal:   {Convert.ToString(number, 8)}"
    printfn $"   Hex:     {Convert.ToString(number, 16)}\n"

// The example displays the following output:
//    -146 (Base 10):
//       Binary:  1111111111111111111111111111111111111111111111111111111101101110
//       Octal:   1777777777777777777556
//       Hex:     ffffffffffffff6e
//
//    11043 (Base 10):
//       Binary:  10101100100011
//       Octal:   25443
//       Hex:     2b23
//
//    2781913 (Base 10):
//       Binary:  1010100111001011011001
//       Octal:   12471331
//       Hex:     2a72d9
Dim numbers() As Long = { -146, 11043, 2781913 }
For Each number In numbers
   Console.WriteLine("{0} (Base 10):", number)
   Console.WriteLine("   Binary:  {0}", Convert.ToString(number, 2))
   Console.WriteLine("   Octal:   {0}", Convert.ToString(number, 8))
   Console.WriteLine("   Hex:     {0}", Convert.ToString(number, 16))
   Console.WriteLine()
Next      
' The example displays the following output:
'    -146 (Base 10):
'       Binary:  1111111111111111111111111111111111111111111111111111111101101110
'       Octal:   1777777777777777777556
'       Hex:     ffffffffffffff6e
'
'    11043 (Base 10):
'       Binary:  10101100100011
'       Octal:   25443
'       Hex:     2b23
'
'    2781913 (Base 10):
'       Binary:  1010100111001011011001
'       Octal:   12471331
'       Hex:     2a72d9

使用非十進位 32 位整數值

除了使用個別長整數做為十進位值之外,您也可以使用長整數值來執行位運算,或使用長整數值的二進位或十六進位標記法。 Int64 值以 63 位表示,而第六四個位則用來做為符號位。 正值是使用正數標記法來表示。 負值在兩個補數標記法中。 當您對 Int64 值執行位運算或使用個別位時,請務必記住這點。 若要在任何兩個非十進位值上執行數值、布林值或比較運算,這兩個值都必須使用相同的標記法。

欄位

MaxValue

代表 Int64 最大的可能值。 這個欄位為常數。

MinValue

代表 Int64 的最小可能值。 這個欄位為常數。

方法

Abs(Int64)

計算值的絕對值。

Clamp(Int64, Int64, Int64)

將值限制為內含最小值和最大值。

CompareTo(Int64)

將這個執行個體與指定的 64 元帶正負號的整數相比較,並傳回它們的相對值指示。

CompareTo(Object)

將這個執行個體與指定的物件相比較,並傳回它們的相對值指示。

CopySign(Int64, Int64)

將值的正負號複製到另一個值的正負號。

CreateChecked<TOther>(TOther)

從值建立目前類型的實例,針對落在目前類型可表示範圍以外的任何值擲回溢位例外狀況。

CreateSaturating<TOther>(TOther)

從值建立目前型別的實例,使落在目前類型可表示範圍以外的任何值飽和。

CreateTruncating<TOther>(TOther)

從值建立目前型別的實例,截斷落在目前類型可表示範圍以外的任何值。

DivRem(Int64, Int64)

計算兩個值的商數和餘數。

Equals(Int64)

傳回值,表示這個執行個體是否等於指定的 Int64 值。

Equals(Object)

傳回值,該值表示這個執行個體是否和指定的物件相等。

GetHashCode()

傳回這個執行個體的雜湊碼。

GetTypeCode()

傳回實值類型 TypeCodeInt64

IsEvenInteger(Int64)

判斷值是否代表偶數整數。

IsNegative(Int64)

判斷值是否為負值。

IsOddInteger(Int64)

判斷值是否代表奇數整數。

IsPositive(Int64)

判斷值是否為正數。

IsPow2(Int64)

判斷值是否為 2 的乘冪。

LeadingZeroCount(Int64)

計算值中前置零的數目。

Log2(Int64)

計算值的 log2。

Max(Int64, Int64)

比較兩個值與大於的計算。

MaxMagnitude(Int64, Int64)

比較兩個值與大於的計算。

Min(Int64, Int64)

比較兩個值與比較較少的計算。

MinMagnitude(Int64, Int64)

比較兩個值與比較較少的計算。

Parse(ReadOnlySpan<Byte>, IFormatProvider)

將 UTF-8 字元的範圍剖析為值。

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

將 UTF-8 字元的範圍剖析為值。

Parse(ReadOnlySpan<Char>, IFormatProvider)

將字元範圍剖析為值。

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

將數字的範圍表示 (使用指定樣式和特定文化特性格式) 轉換為其對等 64 位元帶正負號的整數。

Parse(String)

將數字的字串表示轉換成它的對等 64 位元帶正負號的整數。

Parse(String, IFormatProvider)

將指定特定文化特性格式之數字的字串表示轉換成它的對等 64 位元帶正負號的整數。

Parse(String, NumberStyles)

將指定樣式之數字的字串表示轉換成它的對等 64 位元帶正負號的整數。

Parse(String, NumberStyles, IFormatProvider)

將指定樣式和特定文化特性格式之數字的字串表示轉換成它的對等 64 位元帶正負號的整數。

PopCount(Int64)

計算值中所設定的位數。

RotateLeft(Int64, Int32)

將值向左旋轉指定的數量。

RotateRight(Int64, Int32)

以指定的數量向右旋轉值。

Sign(Int64)

計算值的符號。

ToString()

將這個執行個體的數值轉換為其相等字串表示。

ToString(IFormatProvider)

使用指定的特定文化特性格式資訊,將這個執行個體的數值轉換成它的相等字串表示。

ToString(String)

使用指定格式,將這個執行個體的數值轉換成它的相等字串表示。

ToString(String, IFormatProvider)

使用指定的格式和特定文化特性格式資訊,將這個執行個體的數值轉換成它的相等字串表示。

TrailingZeroCount(Int64)

計算值中尾端零的數目。

TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider)

嘗試將目前實例的值格式化為 UTF-8 到提供的位元組範圍。

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

嘗試將目前長整數執行個體的值格式化為所提供的字元範圍。

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Int64)

嘗試將 UTF-8 字元的範圍剖析為值。

TryParse(ReadOnlySpan<Byte>, Int64)

嘗試將包含數位字串表示的 UTF-8 字元範圍轉換成其對等的 64 位帶正負號整數。

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Int64)

嘗試將 UTF-8 字元的範圍剖析為值。

TryParse(ReadOnlySpan<Char>, IFormatProvider, Int64)

嘗試將字元範圍剖析成值。

TryParse(ReadOnlySpan<Char>, Int64)

將數字的範圍表示轉換為其對等 64 位元帶正負號的整數。 傳回值,該值指出轉換成功或失敗。

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Int64)

將數字的範圍表示 (使用指定樣式和特定文化特性格式) 轉換為其對等 64 位元帶正負號的整數。 傳回值,該值指出轉換成功或失敗。

TryParse(String, IFormatProvider, Int64)

嘗試將字串剖析成值。

TryParse(String, Int64)

將數字的字串表示轉換成它的對等 64 位元帶正負號的整數。 傳回值,該值指出轉換成功或失敗。

TryParse(String, NumberStyles, IFormatProvider, Int64)

將指定樣式和特定文化特性格式之數字的字串表示轉換成它的對等 64 位元帶正負號的整數。 傳回值,該值指出轉換成功或失敗。

明確介面實作

IAdditionOperators<Int64,Int64,Int64>.Addition(Int64, Int64)

將兩個值相加以計算其總和。

IAdditionOperators<Int64,Int64,Int64>.CheckedAddition(Int64, Int64)

將兩個值相加以計算其總和。

IAdditiveIdentity<Int64,Int64>.AdditiveIdentity

取得目前型別的加法識別。

IBinaryInteger<Int64>.GetByteCount()

取得將寫入為 的 TryWriteLittleEndian(Span<Byte>, Int32) 位元組數目。

IBinaryInteger<Int64>.GetShortestBitLength()

取得目前值之最短兩個補數標記法的長度,以位為單位。

IBinaryInteger<Int64>.TryReadBigEndian(ReadOnlySpan<Byte>, Boolean, Int64)

表示 64 位元帶正負號的整數。

IBinaryInteger<Int64>.TryReadLittleEndian(ReadOnlySpan<Byte>, Boolean, Int64)

表示 64 位元帶正負號的整數。

IBinaryInteger<Int64>.TryWriteBigEndian(Span<Byte>, Int32)

嘗試以大到大到大的格式,將目前的值寫入指定的範圍。

IBinaryInteger<Int64>.TryWriteLittleEndian(Span<Byte>, Int32)

嘗試以位元組端格式將目前的值寫入指定的範圍。

IBinaryNumber<Int64>.AllBitsSet

取得已設定所有位的二進位型別實例。

IBitwiseOperators<Int64,Int64,Int64>.BitwiseAnd(Int64, Int64)

計算兩個值的位和 。

IBitwiseOperators<Int64,Int64,Int64>.BitwiseOr(Int64, Int64)

計算兩個值的位或 。

IBitwiseOperators<Int64,Int64,Int64>.ExclusiveOr(Int64, Int64)

計算兩個值的獨佔或兩個值。

IBitwiseOperators<Int64,Int64,Int64>.OnesComplement(Int64)

計算指定值的一補數標記法。

IComparable.CompareTo(Object)

將這個執行個體與指定的物件相比較,並傳回它們的相對值指示。

IComparisonOperators<Int64,Int64,Boolean>.GreaterThan(Int64, Int64)

比較兩個值,以判斷哪一個值更大。

IComparisonOperators<Int64,Int64,Boolean>.GreaterThanOrEqual(Int64, Int64)

比較兩個值,以判斷哪一個值大於或相等。

IComparisonOperators<Int64,Int64,Boolean>.LessThan(Int64, Int64)

比較兩個值,以判斷哪一個值較少。

IComparisonOperators<Int64,Int64,Boolean>.LessThanOrEqual(Int64, Int64)

比較兩個值,以判斷哪一個值小於或相等。

IConvertible.GetTypeCode()

傳回實值類型 TypeCodeInt64

IConvertible.ToBoolean(IFormatProvider)

如需這個成員的說明,請參閱 ToBoolean(IFormatProvider)

IConvertible.ToByte(IFormatProvider)

如需這個成員的說明,請參閱 ToByte(IFormatProvider)

IConvertible.ToChar(IFormatProvider)

如需這個成員的說明,請參閱 ToChar(IFormatProvider)

IConvertible.ToDateTime(IFormatProvider)

不支援此轉換。 嘗試使用這個方法會擲回 InvalidCastException

IConvertible.ToDecimal(IFormatProvider)

如需這個成員的說明,請參閱 ToDecimal(IFormatProvider)

IConvertible.ToDouble(IFormatProvider)

如需這個成員的說明,請參閱 ToDouble(IFormatProvider)

IConvertible.ToInt16(IFormatProvider)

如需這個成員的說明,請參閱 ToInt16(IFormatProvider)

IConvertible.ToInt32(IFormatProvider)

如需這個成員的說明,請參閱 ToInt32(IFormatProvider)

IConvertible.ToInt64(IFormatProvider)

如需這個成員的說明,請參閱 ToInt64(IFormatProvider)

IConvertible.ToSByte(IFormatProvider)

如需這個成員的說明,請參閱 ToSByte(IFormatProvider)

IConvertible.ToSingle(IFormatProvider)

如需這個成員的說明,請參閱 ToSingle(IFormatProvider)

IConvertible.ToType(Type, IFormatProvider)

如需這個成員的說明,請參閱 ToType(Type, IFormatProvider)

IConvertible.ToUInt16(IFormatProvider)

如需這個成員的說明,請參閱 ToUInt16(IFormatProvider)

IConvertible.ToUInt32(IFormatProvider)

如需這個成員的說明,請參閱 ToUInt32(IFormatProvider)

IConvertible.ToUInt64(IFormatProvider)

如需這個成員的說明,請參閱 ToUInt64(IFormatProvider)

IDecrementOperators<Int64>.CheckedDecrement(Int64)

遞減值。

IDecrementOperators<Int64>.Decrement(Int64)

遞減值。

IDivisionOperators<Int64,Int64,Int64>.Division(Int64, Int64)

將一個值除以計算其商數。

IEqualityOperators<Int64,Int64,Boolean>.Equality(Int64, Int64)

比較兩個值以判斷相等。

IEqualityOperators<Int64,Int64,Boolean>.Inequality(Int64, Int64)

比較兩個值以判斷不相等。

IIncrementOperators<Int64>.CheckedIncrement(Int64)

遞增值。

IIncrementOperators<Int64>.Increment(Int64)

遞增值。

IMinMaxValue<Int64>.MaxValue

取得目前型別的最大值。

IMinMaxValue<Int64>.MinValue

取得目前型別的最小值。

IModulusOperators<Int64,Int64,Int64>.Modulus(Int64, Int64)

將兩個值相除以計算其模數或餘數。

IMultiplicativeIdentity<Int64,Int64>.MultiplicativeIdentity

取得目前型別的乘法識別。

IMultiplyOperators<Int64,Int64,Int64>.CheckedMultiply(Int64, Int64)

將兩個值相乘以計算其乘積。

IMultiplyOperators<Int64,Int64,Int64>.Multiply(Int64, Int64)

將兩個值相乘以計算其乘積。

INumber<Int64>.MaxNumber(Int64, Int64)

比較兩個值與計算,如果輸入為 NaN ,則會傳回另一個值。

INumber<Int64>.MinNumber(Int64, Int64)

比較兩個值與計算,如果輸入 NaN 為 ,則會傳回另一個值。

INumberBase<Int64>.IsCanonical(Int64)

判斷值是否在其標準標記法中。

INumberBase<Int64>.IsComplexNumber(Int64)

判斷值是否代表複數。

INumberBase<Int64>.IsFinite(Int64)

判斷值是否有限。

INumberBase<Int64>.IsImaginaryNumber(Int64)

判斷值是否代表純虛數。

INumberBase<Int64>.IsInfinity(Int64)

判斷值是否為無限。

INumberBase<Int64>.IsInteger(Int64)

判斷值是否代表整數。

INumberBase<Int64>.IsNaN(Int64)

判斷值是否為 NaN。

INumberBase<Int64>.IsNegativeInfinity(Int64)

判斷值是否為負無限大。

INumberBase<Int64>.IsNormal(Int64)

判斷值是否正常。

INumberBase<Int64>.IsPositiveInfinity(Int64)

判斷值是否為正無限大。

INumberBase<Int64>.IsRealNumber(Int64)

判斷值是否代表實數。

INumberBase<Int64>.IsSubnormal(Int64)

判斷值是否為不正常。

INumberBase<Int64>.IsZero(Int64)

判斷值是否為零。

INumberBase<Int64>.MaxMagnitudeNumber(Int64, Int64)

比較兩個值與具有更大大小的計算,如果輸入為 NaN ,則會傳回另一個值。

INumberBase<Int64>.MinMagnitudeNumber(Int64, Int64)

比較兩個值與計算,如果輸入為 NaN ,則其大小較小,並傳回其他值。

INumberBase<Int64>.One

取得型別的值 1

INumberBase<Int64>.Radix

取得類型的基數或基底。

INumberBase<Int64>.TryConvertFromChecked<TOther>(TOther, Int64)

表示 64 位元帶正負號的整數。

INumberBase<Int64>.TryConvertFromSaturating<TOther>(TOther, Int64)

表示 64 位元帶正負號的整數。

INumberBase<Int64>.TryConvertFromTruncating<TOther>(TOther, Int64)

表示 64 位元帶正負號的整數。

INumberBase<Int64>.TryConvertToChecked<TOther>(Int64, TOther)

嘗試將目前型別的實例轉換成另一個型別,針對落在目前類型可表示範圍以外的任何值擲回溢位例外狀況。

INumberBase<Int64>.TryConvertToSaturating<TOther>(Int64, TOther)

嘗試將目前型別的實例轉換成另一個類型,使任何落在目前類型可表示範圍以外的值飽和。

INumberBase<Int64>.TryConvertToTruncating<TOther>(Int64, TOther)

嘗試將目前型別的實例轉換成另一個型別,並截斷任何落在目前類型之可表示範圍以外的值。

INumberBase<Int64>.Zero

取得型別的值 0

IShiftOperators<Int64,Int32,Int64>.LeftShift(Int64, Int32)

將指定數量留下的值移位。

IShiftOperators<Int64,Int32,Int64>.RightShift(Int64, Int32)

以指定的數量向右移位值。

IShiftOperators<Int64,Int32,Int64>.UnsignedRightShift(Int64, Int32)

以指定的數量向右移位值。

ISignedNumber<Int64>.NegativeOne

取得型別的值 -1

ISubtractionOperators<Int64,Int64,Int64>.CheckedSubtraction(Int64, Int64)

減去兩個值來計算其差異。

ISubtractionOperators<Int64,Int64,Int64>.Subtraction(Int64, Int64)

減去兩個值來計算其差異。

IUnaryNegationOperators<Int64,Int64>.CheckedUnaryNegation(Int64)

計算值的已核取一元負數。

IUnaryNegationOperators<Int64,Int64>.UnaryNegation(Int64)

計算值的一元負數。

IUnaryPlusOperators<Int64,Int64>.UnaryPlus(Int64)

計算值的一元加號。

適用於

執行緒安全性

此類型的所有成員都是安全線程。 看似修改實例狀態的成員,實際上會傳回以新值初始化的新實例。 如同任何其他類型,讀取和寫入包含此類型實例的共用變數必須受到鎖定保護,以確保執行緒安全。

另請參閱