BigInteger.Negate(BigInteger) Método

Definição

Nega um valor BigInteger especificado.

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

Parâmetros

value
BigInteger

O valor a ser negado.

Retornos

O resultado do parâmetro value multiplicado por um negativo (-1).

Exemplos

O exemplo a seguir ilustra três maneiras de negar o valor de um BigInteger objeto .

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

Comentários

A negação obtém o inverso aditivo de um número. O inverso aditivo de um número é um número que produz um valor igual a zero quando é adicionado ao número original.

O Negate método é implementado para idiomas que não dão suporte a operadores personalizados. Seu comportamento é idêntico à negação usando o operador de negação unário. Além disso, o Negate método é um substituto útil para o operador de negação ao instanciar uma BigInteger variável, conforme mostrado no exemplo a seguir.

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

Aplica-se a

Confira também