BigInteger.Add(BigInteger, BigInteger) 方法

定义

将两个 BigInteger 值相加,并返回结果。Adds two BigInteger values and returns the result.

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

参数

left
BigInteger

要相加的第一个值。The first value to add.

right
BigInteger

要相加的第二个值。The second value to add.

返回

BigInteger

leftright 的和。The sum of left and right.

注解

不支持运算符重载或自定义运算符的语言可以使用 Add 方法来执行使用 BigInteger 值的加法运算。Languages that do not support operator overloading or custom operators can use the Add method to perform addition using BigInteger values.

在实例化 BigInteger 变量时,Add 方法对于加法运算符是一个有用的替代方法,方法是为该变量分配加法运算,如下面的示例中所示。The Add method is a useful substitute for the addition operator when instantiating a BigInteger variable by assigning it a sum that results from addition, as shown in the following example.

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

适用于

另请参阅