# BigInteger.IComparable.CompareTo(Object) 方法

## 定义

`` virtual int System.IComparable.CompareTo(System::Object ^ obj) = IComparable::CompareTo;``
``int IComparable.CompareTo (object obj);``
``Function CompareTo (obj As Object) As Integer Implements IComparable.CompareTo``

obj
Object

#### 返回

Zero 当前实例等于 `obj`The current instance equals `obj`.

#### 异常

`obj` 不是 BigInteger`obj` is not a BigInteger.

## 示例

``````object[] values = { BigInteger.Pow(Int64.MaxValue, 10), null,
12.534, Int64.MaxValue, BigInteger.One };
BigInteger number = UInt64.MaxValue;

foreach (object value in values)
{
try {
Console.WriteLine("Comparing {0} with '{1}': {2}", number, value,
number.CompareTo(value));
}
catch (ArgumentException) {
Console.WriteLine("Unable to compare the {0} value {1} with a BigInteger.",
value.GetType().Name, value);
}
}
// The example displays the following output:
//    Comparing 18446744073709551615 with '4.4555084156466750133735972424E+189': -1
//    Comparing 18446744073709551615 with '': 1
//    Unable to compare the Double value 12.534 with a BigInteger.
//    Unable to compare the Int64 value 9223372036854775807 with a BigInteger.
//    Comparing 18446744073709551615 with '1': 1
``````
``````Dim values() As Object = { BigInteger.Pow(Int64.MaxValue, 10), Nothing,
12.534, Int64.MaxValue, BigInteger.One }
Dim number As BigInteger = UInt64.MaxValue

For Each value As Object In values
Try
Console.WriteLine("Comparing {0} with '{1}': {2}", number, value,
number.CompareTo(value))
Catch e As ArgumentException
Console.WriteLine("Unable to compare the {0} value {1} with a BigInteger.",
value.GetType().Name, value)
End Try
Next
' The example displays the following output:
'    Comparing 18446744073709551615 with '4.4555084156466750133735972424E+189': -1
'    Comparing 18446744073709551615 with '': 1
'    Unable to compare the Double value 12.534 with a BigInteger.
'    Unable to compare the Int64 value 9223372036854775807 with a BigInteger.
'    Comparing 18446744073709551615 with '1': 1
``````

## 注解

`obj` 参数必须为以下参数之一：The `obj` parameter must be one of the following:

• BigInteger其运行时类型的对象。An object whose run-time type is BigInteger.

• 值为 `null`Object 变量。An Object variable whose value is `null`. 如果 `null``obj` 参数的值，则该方法将返回1，指示当前实例大于 `obj`If the value of the `obj` parameter is `null`, the method returns 1, which indicates that the current instance is greater than `obj`.