BigInteger.Multiply(BigInteger, BigInteger) 메서드

정의

BigInteger 값의 곱을 반환합니다.

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

매개 변수

left
BigInteger

곱할 첫 번째 숫자입니다.

right
BigInteger

곱할 두 번째 숫자입니다.

반환

leftright 매개 변수의 곱입니다.

예제

다음 예제에서는 두 개의 긴 정수로 곱하기 위해 시도합니다. 결과가 긴 정수의 범위를 초과하므로 가 OverflowException throw되고 Multiply 메서드가 곱하기 위해 호출됩니다. C#에서는 이 예제와 같이 키워드(keyword) 또는 /checked+ 컴파일러 옵션을 사용하여 checked 숫자 오버플로에서 예외가 throw되는지 확인해야 합니다.

long number1 = 1234567890;
long number2 = 9876543210;
try
{
   long product;
   product = checked(number1 * number2);
}
catch (OverflowException)
{
   BigInteger product;
   product = BigInteger.Multiply(number1, number2);
   Console.WriteLine(product.ToString());
   }
Dim number1 As Long = 1234567890
Dim number2 As Long = 9876543210
Try
   Dim product As Long
   product = number1 * number2
   Console.WriteLine(product.ToString("N0"))
Catch e As OverflowException
   Dim product As BigInteger
   product = BigInteger.Multiply(number1, number2)
   Console.WriteLine(product.ToString)
End Try

설명

메서드는 Multiply 연산자 오버로드를 지원하지 않는 언어에 대해 구현됩니다. 해당 동작은 곱하기 연산자를 사용하는 곱하기와 동일합니다. 또한 Multiply 메서드는 다음 예제와 같이 곱하기에서 발생하는 제품을 할당하여 변수를 인스턴스화 BigInteger 할 때 곱하기 연산자를 대신하는 유용한 대체 방법입니다.

// The statement
//    BigInteger number = Int64.MaxValue * 3;
// produces compiler error CS0220: The operation overflows at compile time in checked mode.
// The alternative:
BigInteger number = BigInteger.Multiply(Int64.MaxValue, 3);
' The statement
'    Dim number As BigInteger = Int64.MaxValue * 3
' produces compiler error BC30439: Constant expression not representable in type 'Long'.
' The alternative:
Dim number As BigInteger = BigInteger.Multiply(Int64.MaxValue, 3)

필요한 경우 이 메서드는 다른 정수 형식을 개체로 암시적으로 변환합니다 BigInteger . 다음은 메서드가 두 Int64 값으로 전달되는 다음 섹션의 Multiply 예제에 설명되어 있습니다.

적용 대상

추가 정보