Leer en inglés

Compartir a través de


BigInteger.Max(BigInteger, BigInteger) Método

Definición

Devuelve el mayor de dos valores BigInteger.

C#
public static System.Numerics.BigInteger Max(System.Numerics.BigInteger left, System.Numerics.BigInteger right);

Parámetros

left
BigInteger

Primer valor que se va a comparar.

right
BigInteger

Segundo valor que se va a comparar.

Devoluciones

Parámetro left o right, el que sea mayor.

Implementaciones

Ejemplos

En el ejemplo siguiente se usa el Max método para seleccionar el mayor número de una matriz de BigInteger valores.

C#
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)) };
      if (numbers.Length < 2)
      {
         Console.WriteLine("Cannot determine which is the larger of {0} numbers.",
                            numbers.Length);
         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]);

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

      Console.WriteLine("\nThe largest number of the series is:");
      Console.WriteLine("   {0:N0}", 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

Comentarios

Este método corresponde al Math.Max método para tipos numéricos primitivos.

Se aplica a

Producto Versiones
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Consulte también