BigInteger.Equals Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Retorna um valor que indica se dois valores numéricos são iguais.
Sobrecargas
Equals(UInt64) |
Retorna um valor que indica se a instância atual e um inteiro sem sinal de 64 bits têm o mesmo valor. |
Equals(Object) |
Retorna um valor que indica se a instância atual e um objeto especificado têm o mesmo valor. |
Equals(BigInteger) |
Retorna um valor que indica se a instância atual e um objeto BigInteger especificado têm o mesmo valor. |
Equals(Int64) |
Retorna um valor que indica se a instância atual e um inteiro com sinal de 64 bits têm o mesmo valor. |
Equals(UInt64)
- Origem:
- BigInteger.cs
- Origem:
- BigInteger.cs
- Origem:
- BigInteger.cs
Importante
Esta API não está em conformidade com CLS.
Retorna um valor que indica se a instância atual e um inteiro sem sinal de 64 bits têm o mesmo valor.
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
Parâmetros
- other
- UInt64
O inteiro sem sinal de 64 bits para comparar.
Retornos
true
se a instância atual e o inteiro sem sinal de 64 bits tiverem o mesmo valor; caso contrário, false
.
- Atributos
Exemplos
O exemplo a seguir compara a distância aproximada de várias estrelas da Terra com a distância de Epsilon Indi da Terra para determinar se elas são iguais. O exemplo usa cada sobrecarga do Equals método para testar a igualdade.
#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
Comentários
Para determinar a relação entre os dois objetos em vez de apenas testar a igualdade, chame o BigInteger.CompareTo(UInt64) método .
Aplica-se a
Equals(Object)
- Origem:
- BigInteger.cs
- Origem:
- BigInteger.cs
- Origem:
- BigInteger.cs
Retorna um valor que indica se a instância atual e um objeto especificado têm o mesmo valor.
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
Parâmetros
- obj
- Object
O objeto a ser comparado.
Retornos
true
se o obj
argumento for um objeto BigInteger e seu valor for igual ao valor da instância BigInteger atual; caso contrário, false
.
Exemplos
O exemplo a seguir define matrizes e BigInteger paralelasObject. Cada elemento de uma matriz tem o mesmo valor que o elemento correspondente da segunda matriz. Como mostra a saída do exemplo, a instância na BigInteger matriz é considerada igual à instância na Object matriz somente se este for um BigInteger e seus valores forem iguais.
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
Comentários
Se o obj
argumento não for um BigInteger valor, o método retornará false
. O método retornará true
somente se obj
for uma BigInteger instância cujo valor é igual à instância atual.
Para determinar a relação entre os dois objetos em vez de apenas testar a igualdade, chame o CompareTo(Object) método .
Aplica-se a
Equals(BigInteger)
- Origem:
- BigInteger.cs
- Origem:
- BigInteger.cs
- Origem:
- BigInteger.cs
Retorna um valor que indica se a instância atual e um objeto BigInteger especificado têm o mesmo valor.
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
Parâmetros
- other
- BigInteger
O objeto a ser comparado.
Retornos
true
se este objeto BigInteger e other
tiverem o mesmo valor; caso contrário, false
.
Implementações
Exemplos
O exemplo a seguir compara a distância aproximada de várias estrelas da Terra com a distância de Epsilon Indi da Terra para determinar se elas são iguais. O exemplo usa cada sobrecarga do Equals método para testar a igualdade.
#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
Comentários
Esse método implementa a IEquatable<T> interface e tem um desempenho ligeiramente melhor do que Equals(Object) porque não precisa converter o other
parâmetro em um BigInteger objeto .
Para determinar a relação entre os dois BigInteger objetos em vez de apenas testar a igualdade, chame o BigInteger.CompareTo(BigInteger) método .
Aplica-se a
Equals(Int64)
- Origem:
- BigInteger.cs
- Origem:
- BigInteger.cs
- Origem:
- BigInteger.cs
Retorna um valor que indica se a instância atual e um inteiro com sinal de 64 bits têm o mesmo valor.
public:
bool Equals(long other);
public bool Equals (long other);
override this.Equals : int64 -> bool
Public Function Equals (other As Long) As Boolean
Parâmetros
- other
- Int64
O valor inteiro com sinal de 64 bits para comparar.
Retornos
true
se o inteiro com sinal de 64 bits e a instância atual tiverem o mesmo valor; caso contrário, false
.
Exemplos
O exemplo a seguir cria uma instância de um BigInteger objeto de cada tipo integral, exceto UInt64. Em seguida, ele chama o Equals(Int64) método para comparar o BigInteger valor com o valor inteiro original que foi passado para o BigInteger construtor. Como a saída mostra, os valores são iguais em cada caso.
#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
Comentários
Se other
for um Bytevalor , Int16, Int32, UInt16SByte, ou UInt32 , ele será convertido implicitamente em um Int64 valor quando o método for chamado.
Para determinar a relação entre os dois objetos em vez de apenas testar a igualdade, chame o BigInteger.CompareTo(Int64) método .
Aplica-se a
Comentários
https://aka.ms/ContentUserFeedback.
Em breve: Ao longo de 2024, eliminaremos os problemas do GitHub como o mecanismo de comentários para conteúdo e o substituiremos por um novo sistema de comentários. Para obter mais informações, consulteEnviar e exibir comentários de