次の方法で共有


BigInteger.Equals メソッド

定義

2 つの数値が等しいかどうかを示す値を返します。

オーバーロード

Equals(UInt64)

現在のインスタンスの値と符号なし 64 ビット整数の値が等しいかどうかを示す値を返します。

Equals(Object)

現在のインスタンスの値と指定されたオブジェクトの値が等しいかどうかを示す値を返します。

Equals(BigInteger)

現在のインスタンスの値と指定された BigInteger オブジェクトの値が等しいかどうかを示す値を返します。

Equals(Int64)

現在のインスタンスの値と符号付き 64 ビット整数の値が等しいかどうかを示す値を返します。

Equals(UInt64)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
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

属性

次の例では、地球から数個の星のおおよその距離と地球からのイプシロン インディの距離を比較して、それらが等しいかどうかを判断します。 この例では、 メソッドの各オーバーロードを Equals 使用して、等価性をテストします。

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

注釈

等しいかどうかをテストするのではなく、2 つのオブジェクト間のリレーションシップを確認するには、 メソッドを呼び出します BigInteger.CompareTo(UInt64)

適用対象

Equals(Object)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
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

次の例では、並列 Object 配列と BigInteger 配列を定義します。 1 つの配列の各要素は、2 番目の配列の対応する要素と同じ値を持っています。 例の出力に示すように、配列内の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。 メソッドは、 が現在のtrueインスタンスと等しい値をBigInteger持つインスタンスの場合objにのみを返します。

等しいかどうかをテストするのではなく、2 つのオブジェクト間のリレーションシップを確認するには、 メソッドを呼び出します CompareTo(Object)

適用対象

Equals(BigInteger)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
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

実装

次の例では、地球から数個の星のおおよその距離と地球からのイプシロン インディの距離を比較して、それらが等しいかどうかを判断します。 この例では、 メソッドの各オーバーロードを Equals 使用して、等価性をテストします。

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)少し優れたパフォーマンスをBigIntegerother発揮します。

等しいかどうかをテストするのではなく、2 つの BigInteger オブジェクト間のリレーションシップを確認するには、 メソッドを呼び出します BigInteger.CompareTo(BigInteger)

適用対象

Equals(Int64)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
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 比較します。 出力が示すように、値は各ケースで等しくなります。

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

注釈

Byte、、、Int32SByteUInt16または UInt32 の値の場合other、メソッドが呼び出されると、暗黙的に値に変換されますInt64Int16

等しいかどうかをテストするのではなく、2 つのオブジェクト間のリレーションシップを確認するには、 メソッドを呼び出します BigInteger.CompareTo(Int64)

適用対象