C# BigInteger CompareTo(Object)

Description

BigInteger CompareTo(Object) Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object.

Syntax

BigInteger.CompareTo(Object) has the following syntax.


public int CompareTo(
  Object obj
)

Parameters

BigInteger.CompareTo(Object) has the following parameters.

  • obj - The object to compare.

Returns

BigInteger.CompareTo(Object) method returns A signed integer that indicates the relationship of the current instance to the obj parameter, as shown in the following table. Return value Description Less than zero The current instance is less than obj. Zero The current instance equals obj. Greater than zero The current instance is greater than obj, or the obj parameter is null.

Example


using System;//from ww w. j a v a 2s .c  o m
using System.IO;
using System.Numerics;

public class Example
{
   public static void Main()
   {
        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 code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex