C# BigInteger Max

Description

BigInteger Max Returns the larger of two BigInteger values.

Syntax

BigInteger.Max has the following syntax.


public static BigInteger Max(
  BigInteger left,
  BigInteger right
)

Parameters

BigInteger.Max has the following parameters.

  • left - The first value to compare.
  • right - The second value to compare.

Returns

BigInteger.Max method returns The left or right parameter, whichever is larger.

Example


using System;//  w  w w  . j  av  a2  s  .c o m
using System.Numerics;

public class Example
{
   public static void Main()
   {
      BigInteger[] numbers = { Int64.MaxValue * BigInteger.MinusOne, 
                               BigInteger.MinusOne, 
                               10359321239000, 
                               BigInteger.Pow(103988, 2),
                               BigInteger.Multiply(Int32.MaxValue, Int16.MaxValue), 
                               BigInteger.Add(BigInteger.Pow(Int64.MaxValue, 2), 
                               BigInteger.Pow(Int32.MaxValue, 2)) };

      BigInteger largest = numbers[numbers.GetLowerBound(0)];

      for (int ctr = numbers.GetLowerBound(0) + 1; ctr <= numbers.GetUpperBound(0); ctr++)
         largest = BigInteger.Max(largest, numbers[ctr]);

      Console.WriteLine("   {0:N0}", largest);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex