BigInteger.Multiply(BigInteger, BigInteger) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
두 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
곱할 두 번째 숫자입니다.
반품
및 right 매개 변수의 left 곱입니다.
예제
다음 예제에서는 두 개의 긴 정수로 곱하기 위해 시도합니다. 결과가 긴 정수의 범위를 초과하므로 throw OverflowException 되고 Multiply 곱하기 위해 메서드가 호출됩니다. C#에서는 이 예제와 같이 키워드 또는 /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());
}
let number1 = 1234567890L
let number2 = 9876543210L
try
let product: int64 = Checked.(*) number1 number2
()
with :? OverflowException ->
let product = BigInteger.Multiply(number1, number2)
printfn $"{product}"
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);
let 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 나와 있습니다.