BigInteger.Multiply(BigInteger, BigInteger) Yöntem

Tanım

İki BigInteger değerin çarpımını döndürür.

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

Parametreler

left
BigInteger

Çarpacak ilk sayı.

right
BigInteger

Çarpmak için ikinci sayı.

Döndürülenler

ve right parametrelerinin left ürünü.

Örnekler

Aşağıdaki örnek iki uzun tamsayı ile çarpma gerçekleştirmeyi dener. Sonuç uzun bir tamsayı aralığını aştığından, bir OverflowException oluşturulur ve çarpmayı Multiply işlemek için yöntemi çağrılır. C# değerinin sayısal taşmada özel durum oluştuğundan emin olmak için anahtar sözcüğünü (bu örnekte olduğu gibi) veya /checked+ derleyici seçeneğini kullanmanızı checked gerektirdiğini unutmayın.

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

Açıklamalar

Multiply yöntemi, işleç aşırı yüklemesini desteklemeyen diller için uygulanır. Davranışı, çarpma işlecini kullanan çarpma işlemiyle aynıdır. Ayrıca yöntemi, Multiply aşağıdaki örnekte gösterildiği gibi bir değişkene çarpma sonucu veren bir BigInteger ürün atayarak bir değişkenin örneğini oluştururken çarpma işlecinin yerini alır.

// 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)

Gerekirse, bu yöntem diğer tam sayı türlerinin nesnelere örtük dönüştürmesini BigInteger otomatik olarak gerçekleştirir. Bu, yöntemin iki Int64 değer geçirildiği Multiply sonraki bölümdeki örnekte gösterilmiştir.

Şunlara uygulanır

Ayrıca bkz.