BigInteger.Negate(BigInteger) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
对指定的 BigInteger 值求反。
public:
static System::Numerics::BigInteger Negate(System::Numerics::BigInteger value);
public static System.Numerics.BigInteger Negate (System.Numerics.BigInteger value);
static member Negate : System.Numerics.BigInteger -> System.Numerics.BigInteger
Public Shared Function Negate (value As BigInteger) As BigInteger
参数
- value
- BigInteger
要求反的值。
返回
value
参数乘以负一 (-1) 的结果。
示例
下面的示例演示了三种方法来否定对象的值 BigInteger 。
BigInteger number = 12645002;
Console.WriteLine(BigInteger.Negate(number)); // Displays -12645002
Console.WriteLine(-number); // Displays -12645002
Console.WriteLine(number * BigInteger.MinusOne); // Displays -12645002
Dim number As BigInteger = 12645002
Console.WriteLine(BigInteger.Negate(number)) ' Displays -12645002
Console.WriteLine(-number) ' Displays -12645002
Console.WriteLine(number * BigInteger.MinusOne) ' Displays -12645002
注解
求反获取数字的累加反值。 数字的加法反数是一个数字,当它被添加到原始数字时,该数字将产生零的值。
该方法 Negate 针对不支持自定义运算符的语言实现。 其行为与使用一元反数运算符的否定相同。 此外,在实例化BigInteger变量时,该方法Negate对负运算符非常有用,如以下示例所示。
// The statement
// BigInteger number = -Int64.MinValue;
// produces compiler error CS0220: The operation overflows at compile time in checked mode.
// The alternative:
BigInteger number = BigInteger.Negate(Int64.MinValue);
' The statement
' Dim number As BigInteger = -Int64.MinValue
' produces compiler error BC30439: Constant expression not representable in type 'Long'.
' The alternative:
Dim number As BigInteger = BigInteger.Negate(Int64.MinValue)