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

비교할 개체입니다.

반환

Int32

다음 표와 같이 현재 인스턴스와 obj 매개 변수 사이의 관계를 나타내는 부호 있는 정수입니다.

반환 값 설명
0보다 작음 현재 인스턴스가 obj보다 작습니다.
0 현재 인스턴스가 obj와 같습니다.
0보다 큼 현재 인스턴스가 obj보다 크거나 obj 매개 변수가 null입니다.

구현

예외

obj이(가) BigInteger가 아닌 경우

예제

다음 예제에서는 메서드를 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 이면 메서드는 null현재 인스턴스가 1보다 obj크다는 것을 나타내는 1을 반환합니다.

적용 대상

추가 정보