다음을 통해 공유


BigInteger.Min(BigInteger, BigInteger) 메서드

정의

BigInteger 값 중 더 작은 값을 반환합니다.

public:
 static System::Numerics::BigInteger Min(System::Numerics::BigInteger left, System::Numerics::BigInteger right);
public:
 static System::Numerics::BigInteger Min(System::Numerics::BigInteger left, System::Numerics::BigInteger right) = System::Numerics::INumber<System::Numerics::BigInteger>::Min;
public static System.Numerics.BigInteger Min (System.Numerics.BigInteger left, System.Numerics.BigInteger right);
static member Min : System.Numerics.BigInteger * System.Numerics.BigInteger -> System.Numerics.BigInteger
Public Shared Function Min (left As BigInteger, right As BigInteger) As BigInteger

매개 변수

left
BigInteger

비교할 첫 번째 값입니다.

right
BigInteger

비교할 두 번째 값입니다.

반환

left 또는 right 매개 변수 중 더 작은 값입니다.

구현

예제

다음 예제에서는 메서드를 Min 사용하여 값 배열 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)),
                               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.
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))
       BigInteger.Zero |]

if numbers.Length < 2 then
    printfn $"Cannot determine which is the smaller of {numbers.Length} numbers."
else
    let mutable smallest = numbers[0]

    for ctr = 1 to numbers.Length - 1 do
        smallest <- BigInteger.Min(smallest, numbers[ctr])

    printfn "The values:"

    for number in numbers do
        printfn $"{number, 55:N0}"

    printfn "\nThe smallest number of the series is:"
    printfn $"   {smallest: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
//                                                             0
//
//       The smallest number of the series is:
//          -9,223,372,036,854,775,807.
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)),
                                      BigInteger.Zero }
      If numbers.Length < 2 Then 
         Console.WriteLine("Cannot determine which is the smaller of {0} numbers.",
                            numbers.Length)
         Exit Sub
      End If
           
      Dim smallest As BigInteger = numbers(numbers.GetLowerBound(0))
      
      For ctr As Integer = numbers.GetLowerBound(0) + 1 To numbers.GetUpperBound(0)
         smallest = BigInteger.Min(smallest, 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 smallest number of the series is:")
      Console.WriteLine("   {0:N0}", smallest)   
   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
'                                                             0
'       
'       The smallest number of the series is:
'          -9,223,372,036,854,775,807.

설명

이 메서드는 기본 숫자 형식의 Math.Min 메서드에 해당합니다.

적용 대상

추가 정보