BigInteger.IComparable.CompareTo(Object) メソッド

定義

このインスタンスと指定したオブジェクトを比較し、このインスタンスの値が指定したオブジェクトの値よりも小さいか、同じか、または大きいかを示す整数を返します。

 virtual int System.IComparable.CompareTo(System::Object ^ obj) = IComparable::CompareTo;
int IComparable.CompareTo (object obj);
abstract member System.IComparable.CompareTo : obj -> int
override this.System.IComparable.CompareTo : obj -> int
Function CompareTo (obj As Object) As Integer Implements IComparable.CompareTo

パラメーター

obj
Object

比較対象のオブジェクト。

戻り値

現在のインスタンスと obj パラメーターの関係を示す符号付き整数 (次の表を参照)。

戻り値 説明
0 より小さい値 現在のインスタンスは obj より小さい。
ゼロ 現在のインスタンスと obj は等しい。
0 より大きい値 現在のインスタンスは obj より大きい、または obj パラメーターが null である。

実装

例外

objBigInteger ではありません。

次の例では、 メソッドを CompareTo(Object) 呼び出して、オブジェクト配列内の 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 、次のいずれかである必要があります。

  • 実行時の型が である BigIntegerオブジェクト。

  • Object値が であるnull変数。 パラメーターの値が obj の場合、メソッドは null1 を返します。これは、現在のインスタンスが より obj大きいことを示します。

適用対象

こちらもご覧ください