BigInteger.Min Method

Returns the smaller of two BigInteger values.

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

public static BigInteger Min(
	BigInteger left,
	BigInteger right
)

Parameters

left
Type: System.Numerics.BigInteger

The first value to compare.

right
Type: System.Numerics.BigInteger

The second value to compare.

Return Value

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

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

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

using System;
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.Zero };
      if (numbers.Length < 2)
      { 
         Console.WriteLine("Cannot determine which is the smaller of {0} numbers.",
                            numbers.Length);
         return;
      }

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

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

      Console.WriteLine("The values:");
      foreach (BigInteger number in numbers)
         Console.WriteLine("{0,55:N0}", number);

      Console.WriteLine("\nThe smallest number of the series is:");
      Console.WriteLine("   {0:N0}", smallest);
   }
}
// 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 
//                                                             0 
//        
//       The smallest number of the series is: 
//          -9,223,372,036,854,775,807.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft