BigInteger.Equals 方法

定义

返回一个值,该值指示两个数值是否相等。

重载

Equals(UInt64)

返回一个值,该值指示当前实例与 64 位无符号整数是否具有相同的值。

Equals(Object)

返回一个值,该值指示当前实例与指定的对象是否具有相同的值。

Equals(BigInteger)

返回一个值,该值指示当前实例与指定的 BigInteger 对象是否具有相同的值。

Equals(Int64)

返回一个值,该值指示当前实例与 64 位带符号整数是否具有相同的值。

Equals(UInt64)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

重要

此 API 不符合 CLS。

返回一个值,该值指示当前实例与 64 位无符号整数是否具有相同的值。

public:
 bool Equals(System::UInt64 other);
[System.CLSCompliant(false)]
public bool Equals (ulong other);
[<System.CLSCompliant(false)>]
override this.Equals : uint64 -> bool
Public Function Equals (other As ULong) As Boolean

参数

other
UInt64

要比较的 64 位无符号整数。

返回

如果当前实例与 64 位无符号整数具有相同的值,则为 true;否则为 false

属性

示例

以下示例将几颗恒星与地球的近似距离与 Epsilon Indi 与地球的距离进行比较,以确定它们是否相等。 该示例使用 方法的每个重载 Equals 来测试相等性。

#using <System.Numerics.dll>

using namespace System;
using namespace System::Numerics;


void main()
{
   const Int64 LIGHT_YEAR = 5878625373183;

   BigInteger altairDistance = 17 * LIGHT_YEAR;
   BigInteger epsilonIndiDistance = 12 * LIGHT_YEAR;
   BigInteger ursaeMajoris47Distance = 46 * LIGHT_YEAR;
   Int64 tauCetiDistance = 12 * LIGHT_YEAR;
   UInt64 procyon2Distance = 12 * LIGHT_YEAR;
   Object^ wolf424ABDistance = 14 * LIGHT_YEAR;

   Console::WriteLine("Approx. equal distances from Epsilon Indi to:");
   Console::WriteLine("   Altair: {0}",
      epsilonIndiDistance.Equals(altairDistance));
   Console::WriteLine("   Ursae Majoris 47: {0}",
      epsilonIndiDistance.Equals(ursaeMajoris47Distance));
   Console::WriteLine("   TauCeti: {0}",
      epsilonIndiDistance.Equals(tauCetiDistance));
   Console::WriteLine("   Procyon 2: {0}",
      epsilonIndiDistance.Equals(procyon2Distance));
   Console::WriteLine("   Wolf 424 AB: {0}",
      epsilonIndiDistance.Equals(wolf424ABDistance));
}
/*
The example displays output like the following:
      Approx. equal distances from Epsilon Indi to:
      Altair: False
      Ursae Majoris 47: False
      TauCeti: True
      Procyon 2: True
      Wolf 424 AB: False
*/
const long LIGHT_YEAR = 5878625373183;

BigInteger altairDistance = 17 * LIGHT_YEAR;
BigInteger epsilonIndiDistance = 12 * LIGHT_YEAR;
BigInteger ursaeMajoris47Distance = 46 * LIGHT_YEAR;
long tauCetiDistance = 12 * LIGHT_YEAR;
ulong procyon2Distance = 12 * LIGHT_YEAR;
object wolf424ABDistance = 14 * LIGHT_YEAR;

Console.WriteLine("Approx. equal distances from Epsilon Indi to:");
Console.WriteLine("   Altair: {0}",
                  epsilonIndiDistance.Equals(altairDistance));
Console.WriteLine("   Ursae Majoris 47: {0}",
                  epsilonIndiDistance.Equals(ursaeMajoris47Distance));
Console.WriteLine("   TauCeti: {0}",
                  epsilonIndiDistance.Equals(tauCetiDistance));
Console.WriteLine("   Procyon 2: {0}",
                  epsilonIndiDistance.Equals(procyon2Distance));
Console.WriteLine("   Wolf 424 AB: {0}",
                  epsilonIndiDistance.Equals(wolf424ABDistance));
// The example displays the following output:
//    Approx. equal distances from Epsilon Indi to:
//       Altair: False
//       Ursae Majoris 47: False
//       TauCeti: True
//       Procyon 2: True
//       Wolf 424 AB: False
let LIGHT_YEAR = 5878625373183L

let altairDistance = 17I * bigint LIGHT_YEAR
let epsilonIndiDistance = 12I * bigint LIGHT_YEAR
let ursaeMajoris47Distance = 46I * bigint LIGHT_YEAR
let tauCetiDistance = 12L * LIGHT_YEAR
let procyon2Distance = 12uL * uint64 LIGHT_YEAR
let wolf424ABDistance = 14L * LIGHT_YEAR

printfn "Approx. equal distances from Epsilon Indi to:"
printfn $"   Altair: {epsilonIndiDistance.Equals(altairDistance)}"
printfn $"   Ursae Majoris 47: {epsilonIndiDistance.Equals(ursaeMajoris47Distance)}"
printfn $"   TauCeti: {epsilonIndiDistance.Equals(tauCetiDistance)}"
printfn $"   Procyon 2: {epsilonIndiDistance.Equals(procyon2Distance)}"
printfn $"   Wolf 424 AB: {epsilonIndiDistance.Equals(wolf424ABDistance)}"
// The example displays the following output:
//    Approx. equal distances from Epsilon Indi to:
//       Altair: False
//       Ursae Majoris 47: False
//       TauCeti: True
//       Procyon 2: True
//       Wolf 424 AB: False
   Const LIGHT_YEAR As Long = 5878625373183

   Dim altairDistance As BigInteger = 17 * LIGHT_YEAR
   Dim epsilonIndiDistance As BigInteger = 12 * LIGHT_YEAR
   Dim ursaeMajoris47Distance As BigInteger = 46 * LIGHT_YEAR
   Dim tauCetiDistance As BigInteger = 12 * LIGHT_YEAR
   Dim procyon2Distance As Long = 12 * LIGHT_YEAR
   Dim wolf424ABDistance As Object = 14 * LIGHT_YEAR
   
   Console.WriteLine("Approx. equal distances from Epsilon Indi to:")
   Console.WriteLine("   Altair: {0}", _
                     epsilonIndiDistance.Equals(altairDistance))
   Console.WriteLine("   Ursae Majoris 47: {0}", _
                     epsilonIndiDistance.Equals(ursaeMajoris47Distance))
   Console.WriteLine("   TauCeti: {0}", _
                     epsilonIndiDistance.Equals(tauCetiDistance))
   Console.WriteLine("   Procyon 2: {0}", _
                     epsilonIndiDistance.Equals(procyon2Distance))
   Console.WriteLine("   Wolf 424 AB: {0}", _
                     epsilonIndiDistance.Equals(wolf424ABDistance))
   ' The example displays the following output:
   '    Approx. equal distances from Epsilon Indi to:
   '       Altair: False
   '       Ursae Majoris 47: False
   '       TauCeti: True
   '       Procyon 2: True
   '       Wolf 424 AB: False

注解

若要确定两个对象之间的关系,而不只是测试相等性,请调用 BigInteger.CompareTo(UInt64) 方法。

适用于

Equals(Object)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

返回一个值,该值指示当前实例与指定的对象是否具有相同的值。

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object obj);
public override bool Equals (object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

参数

obj
Object

要比较的对象。

返回

如果 obj 参数是 BigInteger 对象,并且其值等于当前 BigInteger 实例的值,则为 true;否则为 false

示例

以下示例定义并行 ObjectBigInteger 数组。 一个数组的每个元素与第二个数组的对应元素具有相同的值。 如示例输出所示,仅当数组中的BigInteger实例为 且BigInteger其值相等时,数组中的实例才被视为等于数组中的 Object 实例。

using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      object[] obj = { 0, 10, 100, new BigInteger(1000), -10 };
      BigInteger[] bi = { BigInteger.Zero, new BigInteger(10),
                          new BigInteger(100), new BigInteger(1000),
                          new BigInteger(-10) };
      for (int ctr = 0; ctr < bi.Length; ctr++)
         Console.WriteLine(bi[ctr].Equals(obj[ctr]));
   }
}
// The example displays the following output:
//       False
//       False
//       False
//       True
//       False
open System.Numerics

let obj: obj[] = [| 0; 10; 100; BigInteger 1000; -10 |]

let bi =
    [| BigInteger.Zero
       BigInteger 10
       BigInteger 100
       BigInteger 1000
       BigInteger -10 |]

for ctr = 0 to bi.Length - 1 do
    printfn $"{bi.[ctr].Equals(obj.[ctr])}"
// The example displays the following output:
//       False
//       False
//       False
//       True
//       False
Imports System.Numerics

Module Example
   Public Sub Main()
      Dim obj() As object = { 0, 10, 100, New BigInteger(1000), -10 }
      Dim bi() As BigInteger = { BigInteger.Zero, New BigInteger(10),
                                 New BigInteger(100), New BigInteger(1000),
                                 New BigInteger(-10) }
      For ctr As Integer = 0 To bi.Length - 1
         Console.WriteLine(bi(ctr).Equals(obj(ctr)))
      Next                           
   End Sub
End Module
' The example displays the following output:
'       False
'       False
'       False
'       True
'       False

注解

obj如果 参数不是BigInteger值,则 方法返回 false。 仅当 objBigInteger值等于当前实例的实例时,方法才返回 true

若要确定两个对象之间的关系,而不只是测试相等性,请调用 CompareTo(Object) 方法。

适用于

Equals(BigInteger)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

返回一个值,该值指示当前实例与指定的 BigInteger 对象是否具有相同的值。

public:
 virtual bool Equals(System::Numerics::BigInteger other);
public bool Equals (System.Numerics.BigInteger other);
override this.Equals : System.Numerics.BigInteger -> bool
Public Function Equals (other As BigInteger) As Boolean

参数

other
BigInteger

要比较的对象。

返回

如果此 BigInteger 对象与 other 具有相同的值,则为 true;否则为 false

实现

示例

以下示例将几颗恒星与地球的近似距离与 Epsilon Indi 与地球的距离进行比较,以确定它们是否相等。 该示例使用 方法的每个重载 Equals 来测试相等性。

#using <System.Numerics.dll>

using namespace System;
using namespace System::Numerics;


void main()
{
   const Int64 LIGHT_YEAR = 5878625373183;

   BigInteger altairDistance = 17 * LIGHT_YEAR;
   BigInteger epsilonIndiDistance = 12 * LIGHT_YEAR;
   BigInteger ursaeMajoris47Distance = 46 * LIGHT_YEAR;
   Int64 tauCetiDistance = 12 * LIGHT_YEAR;
   UInt64 procyon2Distance = 12 * LIGHT_YEAR;
   Object^ wolf424ABDistance = 14 * LIGHT_YEAR;

   Console::WriteLine("Approx. equal distances from Epsilon Indi to:");
   Console::WriteLine("   Altair: {0}",
      epsilonIndiDistance.Equals(altairDistance));
   Console::WriteLine("   Ursae Majoris 47: {0}",
      epsilonIndiDistance.Equals(ursaeMajoris47Distance));
   Console::WriteLine("   TauCeti: {0}",
      epsilonIndiDistance.Equals(tauCetiDistance));
   Console::WriteLine("   Procyon 2: {0}",
      epsilonIndiDistance.Equals(procyon2Distance));
   Console::WriteLine("   Wolf 424 AB: {0}",
      epsilonIndiDistance.Equals(wolf424ABDistance));
}
/*
The example displays output like the following:
      Approx. equal distances from Epsilon Indi to:
      Altair: False
      Ursae Majoris 47: False
      TauCeti: True
      Procyon 2: True
      Wolf 424 AB: False
*/
const long LIGHT_YEAR = 5878625373183;

BigInteger altairDistance = 17 * LIGHT_YEAR;
BigInteger epsilonIndiDistance = 12 * LIGHT_YEAR;
BigInteger ursaeMajoris47Distance = 46 * LIGHT_YEAR;
long tauCetiDistance = 12 * LIGHT_YEAR;
ulong procyon2Distance = 12 * LIGHT_YEAR;
object wolf424ABDistance = 14 * LIGHT_YEAR;

Console.WriteLine("Approx. equal distances from Epsilon Indi to:");
Console.WriteLine("   Altair: {0}",
                  epsilonIndiDistance.Equals(altairDistance));
Console.WriteLine("   Ursae Majoris 47: {0}",
                  epsilonIndiDistance.Equals(ursaeMajoris47Distance));
Console.WriteLine("   TauCeti: {0}",
                  epsilonIndiDistance.Equals(tauCetiDistance));
Console.WriteLine("   Procyon 2: {0}",
                  epsilonIndiDistance.Equals(procyon2Distance));
Console.WriteLine("   Wolf 424 AB: {0}",
                  epsilonIndiDistance.Equals(wolf424ABDistance));
// The example displays the following output:
//    Approx. equal distances from Epsilon Indi to:
//       Altair: False
//       Ursae Majoris 47: False
//       TauCeti: True
//       Procyon 2: True
//       Wolf 424 AB: False
let LIGHT_YEAR = 5878625373183L

let altairDistance = 17I * bigint LIGHT_YEAR
let epsilonIndiDistance = 12I * bigint LIGHT_YEAR
let ursaeMajoris47Distance = 46I * bigint LIGHT_YEAR
let tauCetiDistance = 12L * LIGHT_YEAR
let procyon2Distance = 12uL * uint64 LIGHT_YEAR
let wolf424ABDistance = 14L * LIGHT_YEAR

printfn "Approx. equal distances from Epsilon Indi to:"
printfn $"   Altair: {epsilonIndiDistance.Equals(altairDistance)}"
printfn $"   Ursae Majoris 47: {epsilonIndiDistance.Equals(ursaeMajoris47Distance)}"
printfn $"   TauCeti: {epsilonIndiDistance.Equals(tauCetiDistance)}"
printfn $"   Procyon 2: {epsilonIndiDistance.Equals(procyon2Distance)}"
printfn $"   Wolf 424 AB: {epsilonIndiDistance.Equals(wolf424ABDistance)}"
// The example displays the following output:
//    Approx. equal distances from Epsilon Indi to:
//       Altair: False
//       Ursae Majoris 47: False
//       TauCeti: True
//       Procyon 2: True
//       Wolf 424 AB: False
   Const LIGHT_YEAR As Long = 5878625373183

   Dim altairDistance As BigInteger = 17 * LIGHT_YEAR
   Dim epsilonIndiDistance As BigInteger = 12 * LIGHT_YEAR
   Dim ursaeMajoris47Distance As BigInteger = 46 * LIGHT_YEAR
   Dim tauCetiDistance As BigInteger = 12 * LIGHT_YEAR
   Dim procyon2Distance As Long = 12 * LIGHT_YEAR
   Dim wolf424ABDistance As Object = 14 * LIGHT_YEAR
   
   Console.WriteLine("Approx. equal distances from Epsilon Indi to:")
   Console.WriteLine("   Altair: {0}", _
                     epsilonIndiDistance.Equals(altairDistance))
   Console.WriteLine("   Ursae Majoris 47: {0}", _
                     epsilonIndiDistance.Equals(ursaeMajoris47Distance))
   Console.WriteLine("   TauCeti: {0}", _
                     epsilonIndiDistance.Equals(tauCetiDistance))
   Console.WriteLine("   Procyon 2: {0}", _
                     epsilonIndiDistance.Equals(procyon2Distance))
   Console.WriteLine("   Wolf 424 AB: {0}", _
                     epsilonIndiDistance.Equals(wolf424ABDistance))
   ' The example displays the following output:
   '    Approx. equal distances from Epsilon Indi to:
   '       Altair: False
   '       Ursae Majoris 47: False
   '       TauCeti: True
   '       Procyon 2: True
   '       Wolf 424 AB: False

注解

此方法实现 IEquatable<T> 接口,其性能略好于 Equals(Object) ,因为它不必将 参数转换为 otherBigInteger 对象。

若要确定两个 BigInteger 对象之间的关系,而不只是测试相等性,请调用 BigInteger.CompareTo(BigInteger) 方法。

适用于

Equals(Int64)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

返回一个值,该值指示当前实例与 64 位带符号整数是否具有相同的值。

public:
 bool Equals(long other);
public bool Equals (long other);
override this.Equals : int64 -> bool
Public Function Equals (other As Long) As Boolean

参数

other
Int64

要比较的 64 位带符号整数值。

返回

如果 64 位带符号整数与当前实例具有相同的值,则为 true;否则为 false

示例

以下示例实例化 BigInteger 除 以外的 UInt64每个整型类型的 对象。 然后, Equals(Int64) 它调用 方法,将 BigInteger 值与传递给 BigInteger 构造函数的原始整数值进行比较。 如输出所示,每个情况下的值都相等。

#using <System.Numerics.dll>

using namespace System;
using namespace System::Numerics;

void main()
{
   BigInteger bigIntValue;

   Byte byteValue = 16;
   bigIntValue = BigInteger(byteValue);
   Console::WriteLine("{0} {1} = {2} {3} : {4}",
      bigIntValue.GetType()->Name, bigIntValue,
      byteValue.GetType()->Name, byteValue,
      bigIntValue.Equals((Int64)byteValue));

   SByte sbyteValue = -16;
   bigIntValue = BigInteger(sbyteValue);
   Console::WriteLine("{0} {1} = {2} {3} : {4}",
      bigIntValue.GetType()->Name, bigIntValue,
      sbyteValue.GetType()->Name, sbyteValue,
      bigIntValue.Equals((Int64)sbyteValue));

   Int16 shortValue = 1233;
   bigIntValue = BigInteger(shortValue);
   Console::WriteLine("{0} {1} = {2} {3} : {4}",
      bigIntValue.GetType()->Name, bigIntValue,
      shortValue.GetType()->Name, shortValue,
      bigIntValue.Equals((Int64)shortValue));

   UInt16 ushortValue = 64000;
   bigIntValue = BigInteger(ushortValue);
   Console::WriteLine("{0} {1} = {2} {3} : {4}",
      bigIntValue.GetType()->Name, bigIntValue,
      ushortValue.GetType()->Name, ushortValue,
      bigIntValue.Equals((Int64)ushortValue));

   int intValue = -1603854;
   bigIntValue = BigInteger(intValue);
   Console::WriteLine("{0} {1} = {2} {3} : {4}",
      bigIntValue.GetType()->Name, bigIntValue,
      intValue.GetType()->Name, intValue,
      bigIntValue.Equals((Int64)intValue));

   UInt32 uintValue = 1223300;
   bigIntValue = BigInteger(uintValue);
   Console::WriteLine("{0} {1} = {2} {3} : {4}",
      bigIntValue.GetType()->Name, bigIntValue,
      uintValue.GetType()->Name, uintValue,
      bigIntValue.Equals((Int64)uintValue));

   Int64 longValue = -123822229012;
   bigIntValue = BigInteger(longValue);
   Console::WriteLine("{0} {1} = {2} {3} : {4}",
      bigIntValue.GetType()->Name, bigIntValue,
      longValue.GetType()->Name, longValue,
      bigIntValue.Equals((Int64)longValue));
}
/* 
The example displays output like the following:
      BigInteger 16 = Byte 16 : True
      BigInteger -16 = SByte -16 : True
      BigInteger 1233 = Int16 1233 : True
      BigInteger 64000 = UInt16 64000 : True
      BigInteger -1603854 = Int32 -1603854 : True
      BigInteger 1223300 = UInt32 1223300 : True
      BigInteger -123822229012 = Int64 -123822229012 : True
*/
BigInteger bigIntValue;

byte byteValue = 16;
bigIntValue = new BigInteger(byteValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  byteValue.GetType().Name, byteValue,
                  bigIntValue.Equals(byteValue));

sbyte sbyteValue = -16;
bigIntValue = new BigInteger(sbyteValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  sbyteValue.GetType().Name, sbyteValue,
                  bigIntValue.Equals(sbyteValue));

short shortValue = 1233;
bigIntValue = new BigInteger(shortValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  shortValue.GetType().Name, shortValue,
                  bigIntValue.Equals(shortValue));

ushort ushortValue = 64000;
bigIntValue = new BigInteger(ushortValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  ushortValue.GetType().Name, ushortValue,
                  bigIntValue.Equals(ushortValue));

int intValue = -1603854;
bigIntValue = new BigInteger(intValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  intValue.GetType().Name, intValue,
                  bigIntValue.Equals(intValue));

uint uintValue = 1223300;
bigIntValue = new BigInteger(uintValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  uintValue.GetType().Name, uintValue,
                  bigIntValue.Equals(uintValue));

long longValue = -123822229012;
bigIntValue = new BigInteger(longValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  longValue.GetType().Name, longValue,
                  bigIntValue.Equals(longValue));
// The example displays the following output:
//    BigInteger 16 = Byte 16 : True
//    BigInteger -16 = SByte -16 : True
//    BigInteger 1233 = Int16 1233 : True
//    BigInteger 64000 = UInt16 64000 : True
//    BigInteger -1603854 = Int32 -1603854 : True
//    BigInteger 1223300 = UInt32 1223300 : True
//    BigInteger -123822229012 = Int64 -123822229012 : True
let byteValue = 16uy
let bigIntValue = BigInteger byteValue

printfn
    $"{bigIntValue.GetType().Name} {bigIntValue} = {byteValue.GetType().Name} {byteValue} : {bigIntValue.Equals(byteValue)}"

let sbyteValue = -16y
let bigIntValue = BigInteger sbyteValue

printfn
    $"{bigIntValue.GetType().Name} {bigIntValue} = {sbyteValue.GetType().Name} {sbyteValue} : {bigIntValue.Equals(sbyteValue)}"

let shortValue = 1233s
let bigIntValue = BigInteger shortValue

printfn
    $"{bigIntValue.GetType().Name} {bigIntValue} = {shortValue.GetType().Name} {shortValue} : {bigIntValue.Equals(shortValue)}"

let ushortValue = 64000us
let bigIntValue = BigInteger ushortValue

printfn
    $"{bigIntValue.GetType().Name} {bigIntValue} = {ushortValue.GetType().Name} {ushortValue} : {bigIntValue.Equals(ushortValue)}"

let intValue = -1603854
let bigIntValue = BigInteger intValue

printfn
    $"{bigIntValue.GetType().Name} {bigIntValue} = {intValue.GetType().Name} {intValue} : {bigIntValue.Equals(intValue)}"

let uintValue = 1223300u
let bigIntValue = BigInteger uintValue

printfn
    $"{bigIntValue.GetType().Name} {bigIntValue} = {uintValue.GetType().Name} {uintValue} : {bigIntValue.Equals(uintValue)}"

let longValue = -123822229012L
let bigIntValue = BigInteger longValue

printfn
    $"{bigIntValue.GetType().Name} {bigIntValue} = {longValue.GetType().Name} {longValue} : {bigIntValue.Equals(longValue)}"
// The example displays the following output:
//    BigInteger 16 = Byte 16 : True
//    BigInteger -16 = SByte -16 : True
//    BigInteger 1233 = Int16 1233 : True
//    BigInteger 64000 = UInt16 64000 : True
//    BigInteger -1603854 = Int32 -1603854 : True
//    BigInteger 1223300 = UInt32 1223300 : True
//    BigInteger -123822229012 = Int64 -123822229012 : True
Dim bigIntValue As BigInteger 

Dim byteValue As Byte = 16
bigIntValue = New BigInteger(byteValue)
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  byteValue.GetType().Name, byteValue, 
                  bigIntValue.Equals(byteValue))
                  
Dim sbyteValue As SByte = -16
bigIntValue = New BigInteger(sbyteValue)
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  sbyteValue.GetType().Name, sbyteValue,
                  bigIntValue.Equals(sbyteValue))

Dim shortValue As Short = 1233
bigIntValue = New BigInteger(shortValue)
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  shortValue.GetType().Name, shortValue, 
                  bigIntValue.Equals(shortValue))
      
Dim ushortValue As UShort = 64000
bigIntValue = New BigInteger(ushortValue)
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  ushortValue.GetType().Name, ushortValue, 
                  bigIntValue.Equals(ushortValue))

Dim intValue As Integer = -1603854
bigIntValue = New BigInteger(intValue)
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  intValue.GetType().Name, intValue, 
                  bigIntValue.Equals(intValue))

Dim uintValue As UInteger = 1223300
bigIntValue = New BigInteger(uintValue)
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  uintValue.GetType().Name, uintValue, 
                  bigIntValue.Equals(uintValue))

Dim longValue As Long = -123822229012
bigIntValue = New BigInteger(longValue)
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  longValue.GetType().Name, longValue, 
                  bigIntValue.Equals(longValue))
' The example displays the following output:
'    BigInteger 16 = Byte 16 : True
'    BigInteger -16 = SByte -16 : True
'    BigInteger 1233 = Int16 1233 : True
'    BigInteger 64000 = UInt16 64000 : True
'    BigInteger -1603854 = Int32 -1603854 : True
'    BigInteger 1223300 = UInt32 1223300 : True
'    BigInteger -123822229012 = Int64 -123822229012 : True

注解

如果 otherByteInt16Int32SByteUInt16UInt32 值,则调用 方法时,它会隐式转换为 Int64 值。

若要确定两个对象之间的关系,而不只是测试相等性,请调用 BigInteger.CompareTo(Int64) 方法。

适用于