BigInteger.Add(BigInteger, BigInteger) 方法

定义

将两个 BigInteger 值相加,并返回结果。

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

要相加的第一个值。

right
BigInteger

要相加的第二个值。

返回

leftright 的和。

注解

不支持运算符重载或自定义运算符的语言可以使用 Add 方法使用 BigInteger 值执行加法。

在实例化BigInteger变量时,方法Add通过为变量分配加法产生的和来替代加法运算符非常有用,如以下示例所示。

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

适用于

另请参阅