BigInteger.Equals Méthode

Définition

Retourne une valeur qui indique si deux valeurs numériques sont égales.

Surcharges

Equals(UInt64)

Retourne une valeur qui indique si l'instance actuelle et un entier 64 bits non signé ont la même valeur.

Equals(Object)

Retourne une valeur qui indique si l'instance actuelle et un objet spécifié ont la même valeur.

Equals(BigInteger)

Retourne une valeur qui indique si l'instance actuelle et un objet BigInteger spécifié ont la même valeur.

Equals(Int64)

Retourne une valeur qui indique si l'instance actuelle et un entier 64 bits signé ont la même valeur.

Equals(UInt64)

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

Important

Cette API n’est pas conforme CLS.

Retourne une valeur qui indique si l'instance actuelle et un entier 64 bits non signé ont la même valeur.

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

Paramètres

other
UInt64

Entier 64 bits non signé à comparer.

Retours

true si l'instance actuelle et l'entier 64 bits non signé ont la même valeur ; sinon, false.

Attributs

Exemples

L’exemple suivant compare la distance approximative de plusieurs étoiles de la Terre à la distance d’Epsilon Indi par rapport à la Terre pour déterminer si elles sont égales. L’exemple utilise chaque surcharge de la méthode pour tester l’égalité 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
   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

Remarques

Pour déterminer la relation entre les deux objets au lieu de simplement tester l’égalité, appelez la BigInteger.CompareTo(UInt64) méthode .

S’applique à

Equals(Object)

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

Retourne une valeur qui indique si l'instance actuelle et un objet spécifié ont la même valeur.

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

Paramètres

obj
Object

Objet à comparer.

Retours

true si l’argument obj est un objet BigInteger et si sa valeur est égale à la valeur de l’instance BigInteger actuelle ; sinon, false.

Exemples

L’exemple suivant définit des tableaux et BigInteger parallèlesObject. Chaque élément d’un tableau a la même valeur que l’élément correspondant du deuxième tableau. Comme le montre la sortie de l’exemple, l’instance du BigInteger tableau est considérée comme égale à l’instance du Object tableau uniquement si cette dernière est un BigInteger et si ses valeurs sont égales.

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
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

Remarques

Si l’argument obj n’est pas une BigInteger valeur, la méthode retourne false. La méthode retourne true uniquement si obj est une BigInteger instance dont la valeur est égale à l’instance actuelle.

Pour déterminer la relation entre les deux objets au lieu de simplement tester l’égalité, appelez la CompareTo(Object) méthode .

S’applique à

Equals(BigInteger)

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

Retourne une valeur qui indique si l'instance actuelle et un objet BigInteger spécifié ont la même valeur.

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

Paramètres

other
BigInteger

Objet à comparer.

Retours

true si cet objet BigInteger et other ont la même valeur ; sinon, false.

Implémente

Exemples

L’exemple suivant compare la distance approximative de plusieurs étoiles de la Terre à la distance d’Epsilon Indi par rapport à la Terre pour déterminer si elles sont égales. L’exemple utilise chaque surcharge de la méthode pour tester l’égalité 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
   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

Remarques

Cette méthode implémente l’interface IEquatable<T> et fonctionne légèrement mieux que Equals(Object) parce qu’elle n’a pas besoin de convertir le other paramètre en objet BigInteger .

Pour déterminer la relation entre les deux BigInteger objets au lieu de simplement tester l’égalité, appelez la BigInteger.CompareTo(BigInteger) méthode .

S’applique à

Equals(Int64)

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

Retourne une valeur qui indique si l'instance actuelle et un entier 64 bits signé ont la même valeur.

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

Paramètres

other
Int64

Valeur entière 64 bits signée à comparer.

Retours

true si l'entier 64 bits signé et l'instance actuelle ont la même valeur ; sinon, false.

Exemples

L’exemple suivant instancie un BigInteger objet de chaque type intégral à l’exception UInt64de . Il appelle ensuite la Equals(Int64) méthode pour comparer la BigInteger valeur avec la valeur entière d’origine qui a été passée au BigInteger constructeur. Comme le montre la sortie, les valeurs sont égales dans chaque cas.

#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
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

Remarques

Si other est une Bytevaleur , Int16, SByteInt32, UInt16, ou , elle UInt32 est convertie implicitement en valeur Int64 lorsque la méthode est appelée.

Pour déterminer la relation entre les deux objets au lieu de simplement tester l’égalité, appelez la BigInteger.CompareTo(Int64) méthode .

S’applique à