C# BigInteger CompareTo(Int64)
Description
BigInteger CompareTo(Int64)
Compares this instance
to a signed 64-bit integer and returns an integer that indicates whether
the value of this instance is less than, equal to, or greater than the value
of the signed 64-bit integer.
Syntax
BigInteger.CompareTo(Int64)
has the following syntax.
public int CompareTo(
long other
)
Parameters
BigInteger.CompareTo(Int64)
has the following parameters.
other
- The signed 64-bit integer to compare.
Returns
BigInteger.CompareTo(Int64)
method returns A signed integer value that indicates the relationship of this instance
to other, as shown in the following table. Return value Description Less
than zero The current instance is less than other. Zero The current instance
equals other. Greater than zero The current instance is greater than other.
Example
using System;/*from w w w .j a va 2 s . c om*/
using System.IO;
using System.Numerics;
public class Example
{
public static void Main()
{
BigInteger bigIntValue = BigInteger.Parse("12312312312312312312");
byte byteValue = 16;
sbyte sbyteValue = -16;
short shortValue = 1233;
ushort ushortValue = 1233;
int intValue = -12233;
uint uintValue = 12233;
long longValue = 12382222;
ulong ulongValue = 1238222;
Console.WriteLine("Comparing {0} with {1}: {2}",
bigIntValue, byteValue,
bigIntValue.CompareTo(byteValue));
Console.WriteLine("Comparing {0} with {1}: {2}",
bigIntValue, sbyteValue,
bigIntValue.CompareTo(sbyteValue));
Console.WriteLine("Comparing {0} with {1}: {2}",
bigIntValue, shortValue,
bigIntValue.CompareTo(shortValue));
Console.WriteLine("Comparing {0} with {1}: {2}",
bigIntValue, ushortValue,
bigIntValue.CompareTo(ushortValue));
Console.WriteLine("Comparing {0} with {1}: {2}",
bigIntValue, intValue,
bigIntValue.CompareTo(intValue));
Console.WriteLine("Comparing {0} with {1}: {2}",
bigIntValue, uintValue,
bigIntValue.CompareTo(uintValue));
Console.WriteLine("Comparing {0} with {1}: {2}",
bigIntValue, longValue,
bigIntValue.CompareTo(longValue));
Console.WriteLine("Comparing {0} with {1}: {2}",
bigIntValue, ulongValue,
bigIntValue.CompareTo(ulongValue));
}
}
The code above generates the following result.