C# BigInteger CompareTo(BigInteger)

Description

BigInteger CompareTo(BigInteger) Compares this instance to a second BigInteger 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(BigInteger) has the following syntax.


public int CompareTo(
  BigInteger other
)

Parameters

BigInteger.CompareTo(BigInteger) has the following parameters.

  • other - The object to compare.

Returns

BigInteger.CompareTo(BigInteger) 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

The following example illustrates the use of the CompareTo(BigInteger) method to order a list of StarInfo objects.


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

public class Example
{
   public static void Main()
   {
        BigInteger number1 = BigInteger.Pow(Int64.MaxValue, 100);
        BigInteger number2 = number1 + 1;
        string relation = "";
        switch (number1.CompareTo(number2))
        {
           case -1:
              relation = "<";
              break;
           case 0:
              relation = "=";
              break;
           case 1:
              relation = ">";
              break;
        }
        Console.WriteLine("{0} {1} {2}", number1, relation, number2);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex