BigInteger.Negate(BigInteger) Metodo

Definizione

Nega un valore BigInteger specificato.

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

Parametri

value
BigInteger

Valore da negare.

Restituisce

BigInteger

Risultato del parametro value moltiplicato per il valore uno negativo (-1).

Esempio

L'esempio seguente illustra tre modi per negare il valore di un BigInteger oggetto.

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

Commenti

La negazione ottiene l'inverso dell'aggiunta di un numero. L'inverso aggiuntivo di un numero è un numero che produce un valore pari a zero quando viene aggiunto al numero originale.

Il Negate metodo viene implementato per le lingue che non supportano operatori personalizzati. Il suo comportamento è identico alla negazione usando l'operatore di negazione unario. Inoltre, il Negate metodo è un utile sostituto per l'operatore di negazione quando si crea un'istanza di una BigInteger variabile, come illustrato nell'esempio seguente.

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

Si applica a

Vedi anche