BigInteger.Compare(BigInteger, BigInteger) Método

Definición

Compara dos valores BigInteger y devuelve un entero que indica si el primer valor es menor, igual o mayor que el segundo.Compares two BigInteger values and returns an integer that indicates whether the first value is less than, equal to, or greater than the second value.

public:
 static int Compare(System::Numerics::BigInteger left, System::Numerics::BigInteger right);
public static int Compare (System.Numerics.BigInteger left, System.Numerics.BigInteger right);
static member Compare : System.Numerics.BigInteger * System.Numerics.BigInteger -> int
Public Shared Function Compare (left As BigInteger, right As BigInteger) As Integer

Parámetros

left
BigInteger

Primer valor que se va a comparar.The first value to compare.

right
BigInteger

Segundo valor que se va a comparar.The second value to compare.

Devoluciones

Entero con signo que indica los valores relativos de left y right, como se muestra en la tabla siguiente.A signed integer that indicates the relative values of left and right, as shown in the following table.

ValueValue CondiciónCondition
Menor que ceroLess than zero left es menor que right.left is less than right.
CeroZero left es igual que right.left equals right.
Mayor que ceroGreater than zero left es mayor que right.left is greater than right.

Comentarios

Aunque el tipo de BigInteger no tiene ningún intervalo fijo, las comparaciones de los valores de BigInteger no se caracterizan por la falta de precisión que caracteriza la comparación de números de punto flotante.Although the BigInteger type has no fixed range, comparisons of BigInteger values are not characterized by the lack of precision that characterizes the comparison of floating-point numbers. En el ejemplo siguiente se comparan dos valores BigInteger que difieren en uno y que cada uno tiene 1.896 dígitos.The following example compares two BigInteger values that differ by one and that each have 1,896 digits. El método Compare informa correctamente de que los dos valores no son iguales.The Compare method correctly reports that the two values are not equal.

BigInteger number1 = BigInteger.Pow(Int64.MaxValue, 100);
BigInteger number2 = number1 + 1;
string relation = "";
switch (BigInteger.Compare(number1, number2))
{
   case -1:
      relation = "<";
      break;
   case 0:
      relation = "=";
      break;
   case 1:
      relation = ">";
      break;
}
Console.WriteLine("{0} {1} {2}", number1, relation, number2);
// The example displays the following output:
//    3.0829940252776347122742186219E+1896 < 3.0829940252776347122742186219E+1896
Dim number1 As BigInteger = BigInteger.Pow(Int64.MaxValue, 100)
Dim number2 As BigInteger = number1 + 1
Dim relation As String = ""
Select Case BigInteger.Compare(number1, number2)
   Case -1
      relation = "<"
   Case 0
      relation = "="
   Case 1
      relation = ">"
End Select            
Console.WriteLine("{0} {1} {2}", number1, relation, number2)
' The example displays the following output:
'    3.0829940252776347122742186219E+1896 < 3.0829940252776347122742186219E+1896

Se aplica a

Consulte también: