BigInteger.IComparable.CompareTo(Object) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bu örneği belirtilen bir nesneyle karşılaştırır ve bu örneğin değerinin belirtilen nesnenin değerinden küçük, buna eşit veya ondan büyük olup olmadığını gösteren bir tamsayı döndürür.
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
Parametreler
- obj
- Object
Karşılaştırma yapılacak nesne.
Döndürülenler
Aşağıdaki tabloda gösterildiği gibi geçerli örneğin parametreyle obj ilişkisini gösteren imzalı tamsayı.
| Dönüş değeri | Açıklama |
|---|---|
| Sıfırdan küçük | Geçerli örnek değerinden objküçük. |
| Sıfır | Geçerli örnek eşittir obj. |
| Sıfırdan büyük | Geçerli örnek değerinden objobj büyük veya parametresidirnull. |
Uygulamalar
Özel durumlar
obj bir BigIntegerdeğildir.
Örnekler
Aşağıdaki örnek, bir değeri bir CompareTo(Object) nesne dizisindeki her öğeyle karşılaştırmak için yöntemini çağırırBigInteger:
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
let values =
[| BigInteger.Pow(Int64.MaxValue, 10)
Unchecked.defaultof<bigint>
bigint 12.534
Int64.MaxValue
BigInteger.One |]
let number = bigint UInt64.MaxValue
for value in values do
try
printfn $"Comparing {number} with '{value}': {number.CompareTo value}"
with :? ArgumentException as e ->
printfn $"Unable to compare the {value.GetType().Name} value {value} with a BigInteger."
// 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
Açıklamalar
obj parametresi aşağıdakilerden biri olmalıdır:
Çalışma zamanı türü olan bir nesne.BigInteger
Object Değeri olan bir değişken.
nullparametresininobjdeğeri isenull, yöntemi geçerli örneğin değerindenobjbüyük olduğunu gösteren 1 döndürür.