Leer en inglés

Compartir a través de


BigInteger.Negate(BigInteger) Método

Definición

Crea el negativo de un valor BigInteger especificado.

C#
public static System.Numerics.BigInteger Negate(System.Numerics.BigInteger value);

Parámetros

value
BigInteger

Valor que se va a negar.

Devoluciones

Resultado del parámetro value multiplicado por menos uno (-1).

Ejemplos

En el ejemplo siguiente se muestran tres maneras de negar el valor de un BigInteger objeto .

C#
BigInteger number = 12645002;

Console.WriteLine(BigInteger.Negate(number));        // Displays -12645002
Console.WriteLine(-number);                          // Displays -12645002
Console.WriteLine(number * BigInteger.MinusOne);     // Displays -12645002

Comentarios

La negación obtiene el inverso aditivo de un número. El inverso aditivo de un número es un número que genera un valor de cero cuando se agrega al número original.

El Negate método se implementa para lenguajes que no admiten operadores personalizados. Su comportamiento es idéntico a la negación mediante el operador de negación unaria. Además, el Negate método es un sustituto útil del operador de negación al crear una instancia de una BigInteger variable, como se muestra en el ejemplo siguiente.

C#
// 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);

Se aplica a

Producto Versiones
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Consulte también