BigInteger.Max Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns the larger of two BigInteger values.

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

Syntax

'Declaration
Public Shared Function Max ( _
    left As BigInteger, _
    right As BigInteger _
) As BigInteger
public static BigInteger Max(
    BigInteger left,
    BigInteger right
)

Parameters

Return Value

Type: System.Numerics.BigInteger
The left or right parameter, whichever is larger.

Remarks

This method corresponds to the Math.Max method for primitive numeric types.

Examples

The following example uses the Max method to select the largest number in an array of BigInteger values.

Imports System.Numerics

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.FontFamily = New System.Windows.Media.FontFamily("Courier New")       
      Dim numbers() As BigInteger = { 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)) }
      If numbers.Length < 2 Then
         outputBlock.Text += String.Format("Cannot determine which is the larger of {0} numbers.", 
                            numbers.Length) + vbCrLf
         Exit Sub
      End If

      Dim largest As BigInteger = numbers(numbers.GetLowerBound(0))

      For ctr As Integer = numbers.GetLowerBound(0) + 1 To numbers.GetUpperBound(0)
         largest = BigInteger.Max(largest, numbers(ctr))
      Next
      outputBlock.Text &= "The values:" & vbCrLf
      For Each number As BigInteger In numbers
         outputBlock.Text &= String.Format("{0,55}", number) & vbCrLf
      Next
      outputBlock.Text &= vbCrLf
      outputBlock.Text &= "The largest number of the series is:" & vbCrLf
      outputBlock.Text &= String.Format("   {0}", largest) & vbCrLf
   End Sub
End Module
' The example displays the following output:
'       The values:
'                                    -9,223,372,036,854,775,807
'                                                            -1
'                                            10,359,321,239,000
'                                                10,813,504,144
'                                            70,366,596,661,249
'            85,070,591,730,234,615,852,008,593,798,364,921,858
'       
'       The largest number of the series is:
'          85,070,591,730,234,615,852,008,593,798,364,921,858
using System;
using System.Numerics;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.FontFamily = new System.Windows.Media.FontFamily("Courier New");       
      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)) };
      if (numbers.Length < 2)
      {
         outputBlock.Text += String.Format("Cannot determine which is the larger of {0} numbers.",
                            numbers.Length) + "\n";
         return;
      }

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

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

      outputBlock.Text += "The values:" + "\n";
      foreach (BigInteger number in numbers)
         outputBlock.Text += String.Format("{0,55}\n", number);

      outputBlock.Text += "\nThe largest number of the series is:" + "\n";
      outputBlock.Text += String.Format("   {0}\n", largest);
   }
}
// The example displays the following output:
//       The values:
//                                    -9,223,372,036,854,775,807
//                                                            -1
//                                            10,359,321,239,000
//                                                10,813,504,144
//                                            70,366,596,661,249
//            85,070,591,730,234,615,852,008,593,798,364,921,858
//       
//       The largest number of the series is:
//          85,070,591,730,234,615,852,008,593,798,364,921,858

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.