BigInteger.Negate(BigInteger) Metoda

Definicja

Neguje określoną BigInteger wartość.

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

Parametry

value
BigInteger

Wartość do wskazania ujemnej.

Zwraca

Wynik parametru value pomnożony przez ujemny (-1).

Przykłady

W poniższym przykładzie przedstawiono trzy sposoby negowania wartości BigInteger obiektu.

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

Uwagi

Negacja uzyskuje odwrotność dodawania liczby. Odwrotność dodawania liczby to liczba, która generuje wartość zero po dodaniu jej do oryginalnej liczby.

Metoda Negate jest implementowana dla języków, które nie obsługują operatorów niestandardowych. Jego zachowanie jest identyczne z negacją przy użyciu operatora negacji jednoargumentowej. Ponadto Negate metoda jest przydatnym substytutem operatora negacji podczas tworzenia wystąpienia zmiennej BigInteger , jak pokazano w poniższym przykładzie.

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

Dotyczy

Zobacz też