BigInteger.Max(BigInteger, BigInteger) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回兩個 BigInteger 值的較大值。
public:
static System::Numerics::BigInteger Max(System::Numerics::BigInteger left, System::Numerics::BigInteger right);
public:
static System::Numerics::BigInteger Max(System::Numerics::BigInteger left, System::Numerics::BigInteger right) = System::Numerics::INumber<System::Numerics::BigInteger>::Max;
public static System.Numerics.BigInteger Max (System.Numerics.BigInteger left, System.Numerics.BigInteger right);
static member Max : System.Numerics.BigInteger * System.Numerics.BigInteger -> System.Numerics.BigInteger
Public Shared Function Max (left As BigInteger, right As BigInteger) As BigInteger
參數
- left
- BigInteger
要比較的第一個值。
- right
- BigInteger
要比較的第二個值。
傳回
left
或 right
參數,擇一較大者。
實作
範例
下列範例會 Max 使用 方法,在值數組 BigInteger 中選取最大數目。
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
open System
open System.Numerics
let numbers =
[| bigint Int64.MaxValue * BigInteger.MinusOne
BigInteger.MinusOne
10359321239000I
BigInteger.Pow(103988I, 2)
BigInteger.Multiply(Int32.MaxValue, Int16.MaxValue)
BigInteger.Add(BigInteger.Pow(Int64.MaxValue, 2), BigInteger.Pow(Int32.MaxValue, 2)) |]
if numbers.Length < 2 then
printfn $"Cannot determine which is the larger of {numbers.Length} numbers."
else
let mutable largest = numbers[0]
for ctr = 1 to numbers.Length - 1 do
largest <- BigInteger.Max(largest, numbers[ctr])
printfn "The values:"
for number in numbers do
printfn $"{number, 55:N0}"
printfn "\nThe largest number of the series is:"
printfn $" {largest:N0}"
// 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
Imports System.Numerics
Module Example
Public Sub Main()
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
Console.WriteLine("Cannot determine which is the larger of {0} numbers.",
numbers.Length)
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
Console.WriteLine("The values:")
For Each number As BigInteger In numbers
Console.WriteLine("{0,55:N0}", number)
Next
Console.WriteLine()
Console.WriteLine("The largest number of the series is:")
Console.WriteLine(" {0:N0}", largest)
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
備註
這個方法會對應至 Math.Max 基本數值類型的方法。