# BigInteger.Compare(BigInteger, BigInteger) メソッド

## 定義

2 つの BigInteger 値を比較し、1 番目の値が 2 番目の値よりも小さいか、同じか、または大きいかを示す整数を返します。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``

left
BigInteger

right
BigInteger

#### 戻り値

`left``right` の相対値を示す符号付き整数。次の表を参照してください。A signed integer that indicates the relative values of `left` and `right`, as shown in the following table.

Value 条件Condition
ゼロより小さいLess than zero `left``right`がスローされます。`left` is less than `right`.
ゼロZero `left``right` は等しい。`left` equals `right`.
0 より大きい値Greater than zero `left``right`がスローされます。`left` is greater than `right`.

## 注釈

BigInteger の型には固定の範囲がありませんが、BigInteger 値の比較は、浮動小数点数の比較を特徴付ける精度がないことによって特徴付けられません。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. 次の例では、2つの BigInteger 値が異なっていて、それぞれが1896の数字を持つ2つの値を比較しています。The following example compares two BigInteger values that differ by one and that each have 1,896 digits. Compare メソッドは、2つの値が等しくないことを正しく報告します。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
``````