BigInteger Struct

Definizione

Rappresenta un intero con segno arbitrariamente grande.

public value class BigInteger : IComparable, IComparable<System::Numerics::BigInteger>, IEquatable<System::Numerics::BigInteger>, IFormattable
public value class BigInteger : IComparable, IComparable<System::Numerics::BigInteger>, IEquatable<System::Numerics::BigInteger>, ISpanFormattable
public value class BigInteger : IComparable<System::Numerics::BigInteger>, IEquatable<System::Numerics::BigInteger>, IParsable<System::Numerics::BigInteger>, ISpanParsable<System::Numerics::BigInteger>, System::Numerics::IAdditionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IAdditiveIdentity<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IBinaryInteger<System::Numerics::BigInteger>, System::Numerics::IBinaryNumber<System::Numerics::BigInteger>, System::Numerics::IBitwiseOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IComparisonOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, bool>, System::Numerics::IDecrementOperators<System::Numerics::BigInteger>, System::Numerics::IDivisionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IEqualityOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, bool>, System::Numerics::IIncrementOperators<System::Numerics::BigInteger>, System::Numerics::IModulusOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IMultiplicativeIdentity<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IMultiplyOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::INumber<System::Numerics::BigInteger>, System::Numerics::INumberBase<System::Numerics::BigInteger>, System::Numerics::IShiftOperators<System::Numerics::BigInteger, int, System::Numerics::BigInteger>, System::Numerics::ISignedNumber<System::Numerics::BigInteger>, System::Numerics::ISubtractionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IUnaryNegationOperators<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IUnaryPlusOperators<System::Numerics::BigInteger, System::Numerics::BigInteger>
public value class BigInteger : IComparable<System::Numerics::BigInteger>, IEquatable<System::Numerics::BigInteger>, IParsable<System::Numerics::BigInteger>, ISpanParsable<System::Numerics::BigInteger>, IUtf8SpanParsable<System::Numerics::BigInteger>, System::Numerics::IAdditionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IAdditiveIdentity<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IBinaryInteger<System::Numerics::BigInteger>, System::Numerics::IBinaryNumber<System::Numerics::BigInteger>, System::Numerics::IBitwiseOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IComparisonOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, bool>, System::Numerics::IDecrementOperators<System::Numerics::BigInteger>, System::Numerics::IDivisionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IEqualityOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, bool>, System::Numerics::IIncrementOperators<System::Numerics::BigInteger>, System::Numerics::IModulusOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IMultiplicativeIdentity<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IMultiplyOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::INumber<System::Numerics::BigInteger>, System::Numerics::INumberBase<System::Numerics::BigInteger>, System::Numerics::IShiftOperators<System::Numerics::BigInteger, int, System::Numerics::BigInteger>, System::Numerics::ISignedNumber<System::Numerics::BigInteger>, System::Numerics::ISubtractionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IUnaryNegationOperators<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IUnaryPlusOperators<System::Numerics::BigInteger, System::Numerics::BigInteger>
public struct BigInteger : IComparable, IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IFormattable
public readonly struct BigInteger : IComparable, IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IFormattable
public readonly struct BigInteger : IComparable, IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, ISpanFormattable
public readonly struct BigInteger : IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IParsable<System.Numerics.BigInteger>, ISpanParsable<System.Numerics.BigInteger>, System.Numerics.IAdditionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IAdditiveIdentity<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IBinaryInteger<System.Numerics.BigInteger>, System.Numerics.IBinaryNumber<System.Numerics.BigInteger>, System.Numerics.IBitwiseOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IComparisonOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,bool>, System.Numerics.IDecrementOperators<System.Numerics.BigInteger>, System.Numerics.IDivisionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IEqualityOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,bool>, System.Numerics.IIncrementOperators<System.Numerics.BigInteger>, System.Numerics.IModulusOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IMultiplicativeIdentity<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IMultiplyOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.INumber<System.Numerics.BigInteger>, System.Numerics.INumberBase<System.Numerics.BigInteger>, System.Numerics.IShiftOperators<System.Numerics.BigInteger,int,System.Numerics.BigInteger>, System.Numerics.ISignedNumber<System.Numerics.BigInteger>, System.Numerics.ISubtractionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IUnaryNegationOperators<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IUnaryPlusOperators<System.Numerics.BigInteger,System.Numerics.BigInteger>
public readonly struct BigInteger : IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IParsable<System.Numerics.BigInteger>, ISpanParsable<System.Numerics.BigInteger>, IUtf8SpanParsable<System.Numerics.BigInteger>, System.Numerics.IAdditionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IAdditiveIdentity<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IBinaryInteger<System.Numerics.BigInteger>, System.Numerics.IBinaryNumber<System.Numerics.BigInteger>, System.Numerics.IBitwiseOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IComparisonOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,bool>, System.Numerics.IDecrementOperators<System.Numerics.BigInteger>, System.Numerics.IDivisionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IEqualityOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,bool>, System.Numerics.IIncrementOperators<System.Numerics.BigInteger>, System.Numerics.IModulusOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IMultiplicativeIdentity<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IMultiplyOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.INumber<System.Numerics.BigInteger>, System.Numerics.INumberBase<System.Numerics.BigInteger>, System.Numerics.IShiftOperators<System.Numerics.BigInteger,int,System.Numerics.BigInteger>, System.Numerics.ISignedNumber<System.Numerics.BigInteger>, System.Numerics.ISubtractionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IUnaryNegationOperators<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IUnaryPlusOperators<System.Numerics.BigInteger,System.Numerics.BigInteger>
[System.Serializable]
public struct BigInteger : IComparable, IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IFormattable
type BigInteger = struct
    interface IFormattable
type BigInteger = struct
    interface ISpanFormattable
    interface IFormattable
type BigInteger = struct
    interface IFormattable
    interface IParsable<BigInteger>
    interface ISpanFormattable
    interface ISpanParsable<BigInteger>
    interface IAdditionOperators<BigInteger, BigInteger, BigInteger>
    interface IAdditiveIdentity<BigInteger, BigInteger>
    interface IBinaryInteger<BigInteger>
    interface IBinaryNumber<BigInteger>
    interface IBitwiseOperators<BigInteger, BigInteger, BigInteger>
    interface IComparisonOperators<BigInteger, BigInteger, bool>
    interface IEqualityOperators<BigInteger, BigInteger, bool>
    interface IDecrementOperators<BigInteger>
    interface IDivisionOperators<BigInteger, BigInteger, BigInteger>
    interface IIncrementOperators<BigInteger>
    interface IModulusOperators<BigInteger, BigInteger, BigInteger>
    interface IMultiplicativeIdentity<BigInteger, BigInteger>
    interface IMultiplyOperators<BigInteger, BigInteger, BigInteger>
    interface INumber<BigInteger>
    interface INumberBase<BigInteger>
    interface ISubtractionOperators<BigInteger, BigInteger, BigInteger>
    interface IUnaryNegationOperators<BigInteger, BigInteger>
    interface IUnaryPlusOperators<BigInteger, BigInteger>
    interface IShiftOperators<BigInteger, int, BigInteger>
    interface ISignedNumber<BigInteger>
type BigInteger = struct
    interface IFormattable
    interface IParsable<BigInteger>
    interface ISpanFormattable
    interface ISpanParsable<BigInteger>
    interface IAdditionOperators<BigInteger, BigInteger, BigInteger>
    interface IAdditiveIdentity<BigInteger, BigInteger>
    interface IBinaryInteger<BigInteger>
    interface IBinaryNumber<BigInteger>
    interface IBitwiseOperators<BigInteger, BigInteger, BigInteger>
    interface IComparisonOperators<BigInteger, BigInteger, bool>
    interface IEqualityOperators<BigInteger, BigInteger, bool>
    interface IDecrementOperators<BigInteger>
    interface IDivisionOperators<BigInteger, BigInteger, BigInteger>
    interface IIncrementOperators<BigInteger>
    interface IModulusOperators<BigInteger, BigInteger, BigInteger>
    interface IMultiplicativeIdentity<BigInteger, BigInteger>
    interface IMultiplyOperators<BigInteger, BigInteger, BigInteger>
    interface INumber<BigInteger>
    interface INumberBase<BigInteger>
    interface ISubtractionOperators<BigInteger, BigInteger, BigInteger>
    interface IUnaryNegationOperators<BigInteger, BigInteger>
    interface IUnaryPlusOperators<BigInteger, BigInteger>
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<BigInteger>
    interface IShiftOperators<BigInteger, int, BigInteger>
    interface ISignedNumber<BigInteger>
[<System.Serializable>]
type BigInteger = struct
    interface IFormattable
Public Structure BigInteger
Implements IComparable, IComparable(Of BigInteger), IEquatable(Of BigInteger), IFormattable
Public Structure BigInteger
Implements IComparable, IComparable(Of BigInteger), IEquatable(Of BigInteger), ISpanFormattable
Public Structure BigInteger
Implements IAdditionOperators(Of BigInteger, BigInteger, BigInteger), IAdditiveIdentity(Of BigInteger, BigInteger), IBinaryInteger(Of BigInteger), IBinaryNumber(Of BigInteger), IBitwiseOperators(Of BigInteger, BigInteger, BigInteger), IComparable(Of BigInteger), IComparisonOperators(Of BigInteger, BigInteger, Boolean), IDecrementOperators(Of BigInteger), IDivisionOperators(Of BigInteger, BigInteger, BigInteger), IEqualityOperators(Of BigInteger, BigInteger, Boolean), IEquatable(Of BigInteger), IIncrementOperators(Of BigInteger), IModulusOperators(Of BigInteger, BigInteger, BigInteger), IMultiplicativeIdentity(Of BigInteger, BigInteger), IMultiplyOperators(Of BigInteger, BigInteger, BigInteger), INumber(Of BigInteger), INumberBase(Of BigInteger), IParsable(Of BigInteger), IShiftOperators(Of BigInteger, Integer, BigInteger), ISignedNumber(Of BigInteger), ISpanParsable(Of BigInteger), ISubtractionOperators(Of BigInteger, BigInteger, BigInteger), IUnaryNegationOperators(Of BigInteger, BigInteger), IUnaryPlusOperators(Of BigInteger, BigInteger)
Public Structure BigInteger
Implements IAdditionOperators(Of BigInteger, BigInteger, BigInteger), IAdditiveIdentity(Of BigInteger, BigInteger), IBinaryInteger(Of BigInteger), IBinaryNumber(Of BigInteger), IBitwiseOperators(Of BigInteger, BigInteger, BigInteger), IComparable(Of BigInteger), IComparisonOperators(Of BigInteger, BigInteger, Boolean), IDecrementOperators(Of BigInteger), IDivisionOperators(Of BigInteger, BigInteger, BigInteger), IEqualityOperators(Of BigInteger, BigInteger, Boolean), IEquatable(Of BigInteger), IIncrementOperators(Of BigInteger), IModulusOperators(Of BigInteger, BigInteger, BigInteger), IMultiplicativeIdentity(Of BigInteger, BigInteger), IMultiplyOperators(Of BigInteger, BigInteger, BigInteger), INumber(Of BigInteger), INumberBase(Of BigInteger), IParsable(Of BigInteger), IShiftOperators(Of BigInteger, Integer, BigInteger), ISignedNumber(Of BigInteger), ISpanParsable(Of BigInteger), ISubtractionOperators(Of BigInteger, BigInteger, BigInteger), IUnaryNegationOperators(Of BigInteger, BigInteger), IUnaryPlusOperators(Of BigInteger, BigInteger), IUtf8SpanParsable(Of BigInteger)
Ereditarietà
BigInteger
Attributi
Implementazioni
IComparable IComparable<BigInteger> IEquatable<BigInteger> IFormattable ISpanFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<BigInteger> IParsable<TSelf> ISpanParsable<BigInteger> ISpanParsable<TSelf> IAdditionOperators<BigInteger,BigInteger,BigInteger> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<BigInteger,BigInteger> IAdditiveIdentity<TSelf,TSelf> IBinaryInteger<BigInteger> IBinaryNumber<BigInteger> IBinaryNumber<TSelf> IBitwiseOperators<BigInteger,BigInteger,BigInteger> IBitwiseOperators<TSelf,TSelf,TSelf> IComparisonOperators<BigInteger,BigInteger,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<BigInteger> IDecrementOperators<TSelf> IDivisionOperators<BigInteger,BigInteger,BigInteger> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<BigInteger,BigInteger,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IIncrementOperators<BigInteger> IIncrementOperators<TSelf> IModulusOperators<BigInteger,BigInteger,BigInteger> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<BigInteger,BigInteger> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<BigInteger,BigInteger,BigInteger> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<BigInteger> INumber<TSelf> INumberBase<BigInteger> INumberBase<TSelf> IShiftOperators<BigInteger,Int32,BigInteger> IShiftOperators<TSelf,Int32,TSelf> ISignedNumber<BigInteger> ISubtractionOperators<BigInteger,BigInteger,BigInteger> ISubtractionOperators<TSelf,TSelf,TSelf> IUnaryNegationOperators<BigInteger,BigInteger> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<BigInteger,BigInteger> IUnaryPlusOperators<TSelf,TSelf> IUtf8SpanFormattable IUtf8SpanParsable<BigInteger> IUtf8SpanParsable<TSelf>

Commenti

Il BigInteger tipo è un tipo non modificabile che rappresenta un intero arbitrariamente grande il cui valore in teoria non ha limiti superiori o inferiori. I membri del BigInteger tipo sono strettamente paralleli a quelli di altri tipi integrali (, Byte, UInt16Int64Int32SByteInt16UInt32e UInt64 tipi). Questo tipo differisce dagli altri tipi integrali in .NET Framework, che hanno un intervallo indicato dalle relative MinValue proprietà e MaxValue .

Nota

Poiché il BigInteger tipo non è modificabile (vedere Mutabilità e BigInteger Structure) e perché non ha limiti superiori o inferiori, OutOfMemoryException è possibile generare un'operazione che causa un aumento troppo elevato di un BigInteger valore.

Creazione di un'istanza di un oggetto BigInteger

È possibile creare un'istanza di un BigInteger oggetto in diversi modi:

  • È possibile usare la new parola chiave e specificare qualsiasi valore integrale o a virgola mobile come parametro per il BigInteger costruttore. I valori a virgola mobile vengono troncati prima che vengano assegnati a BigInteger.) Nell'esempio seguente viene illustrato come usare la parola chiave per creare BigInteger un'istanza new dei valori.

    BigInteger bigIntFromDouble = new BigInteger(179032.6541);
    Console.WriteLine(bigIntFromDouble);
    BigInteger bigIntFromInt64 = new BigInteger(934157136952);
    Console.WriteLine(bigIntFromInt64);
    // The example displays the following output:
    //   179032
    //   934157136952
    
    Dim bigIntFromDouble As New BigInteger(179032.6541)
    Console.WriteLine(bigIntFromDouble)
    Dim bigIntFromInt64 As New BigInteger(934157136952)
    Console.WriteLine(bigIntFromInt64)
    ' The example displays the following output:
    '   179032
    '   934157136952
    
  • È possibile dichiarare una BigInteger variabile e assegnarlo un valore come si farebbe con qualsiasi tipo numerico, purché tale valore sia un tipo integrale. Nell'esempio seguente viene usata l'assegnazione per creare un BigInteger valore da un Int64oggetto .

    long longValue = 6315489358112;
    BigInteger assignedFromLong = longValue;
    Console.WriteLine(assignedFromLong);
    // The example displays the following output:
    //   6315489358112
    
    Dim longValue As Long = 6315489358112      
    Dim assignedFromLong As BigInteger = longValue
    Console.WriteLine(assignedFromLong)
    ' The example displays the following output:
    '   6315489358112
    
  • È possibile assegnare un valore decimale o a virgola mobile a un BigInteger oggetto se si esegue il cast del valore o si converte prima. L'esempio seguente esegue il cast esplicito (in C#) o converte (in Visual Basic) un Double e un Decimal valore in un BigIntegeroggetto .

    BigInteger assignedFromDouble = (BigInteger) 179032.6541;
    Console.WriteLine(assignedFromDouble);
    BigInteger assignedFromDecimal = (BigInteger) 64312.65m;
    Console.WriteLine(assignedFromDecimal);
    // The example displays the following output:
    //   179032
    //   64312
    
    Dim assignedFromDouble As BigInteger = CType(179032.6541, BigInteger)
    Console.WriteLine(assignedFromDouble)   
    Dim assignedFromDecimal As BigInteger = CType(64312.65d, BigInteger)      
    Console.WriteLine(assignedFromDecimal)
    ' The example displays the following output:
    '   179032
    '   64312
    

Questi metodi consentono di creare un'istanza di un BigInteger oggetto il cui valore è compreso nell'intervallo di uno dei tipi numerici esistenti. È possibile creare un'istanza di un BigInteger oggetto il cui valore può superare l'intervallo dei tipi numerici esistenti in uno dei tre modi seguenti:

  • È possibile usare la new parola chiave e fornire una matrice di byte di qualsiasi dimensione per il BigInteger.BigInteger costruttore. Ad esempio:

    byte[] byteArray = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    BigInteger newBigInt = new BigInteger(byteArray);
    Console.WriteLine("The value of newBigInt is {0} (or 0x{0:x}).", newBigInt);
    // The example displays the following output:
    //   The value of newBigInt is 4759477275222530853130 (or 0x102030405060708090a).
    
    Dim byteArray() As Byte = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
    Dim newBigInt As New BigInteger(byteArray)
    Console.WriteLine("The value of newBigInt is {0} (or 0x{0:x}).", newBigInt)    
    ' The example displays the following output:
    '   The value of newBigInt is 4759477275222530853130 (or 0x102030405060708090a).
    
  • È possibile chiamare i Parse metodi o TryParse per convertire la rappresentazione stringa di un numero in un BigIntegeroggetto . Ad esempio:

    string positiveString = "91389681247993671255432112000000";
    string negativeString = "-90315837410896312071002088037140000";
    BigInteger posBigInt = 0;
    BigInteger negBigInt = 0;
    
    try {
       posBigInt = BigInteger.Parse(positiveString);
       Console.WriteLine(posBigInt);
    }
    catch (FormatException)
    {
       Console.WriteLine("Unable to convert the string '{0}' to a BigInteger value.",
                         positiveString);
    }
    
    if (BigInteger.TryParse(negativeString, out negBigInt))
      Console.WriteLine(negBigInt);
    else
       Console.WriteLine("Unable to convert the string '{0}' to a BigInteger value.",
                          negativeString);
    
    // The example displays the following output:
    //   9.1389681247993671255432112E+31
    //   -9.0315837410896312071002088037E+34
    
    Dim positiveString As String = "91389681247993671255432112000000"
    Dim negativeString As string = "-90315837410896312071002088037140000"
    Dim posBigInt As BigInteger = 0
    Dim negBigInt As BigInteger = 0
    
    Try
       posBigInt = BigInteger.Parse(positiveString)
       Console.WriteLine(posBigInt)
    Catch e As FormatException
       Console.WriteLine("Unable to convert the string '{0}' to a BigInteger value.", _
                         positiveString)
    End Try
    
    If BigInteger.TryParse(negativeString, negBigInt) Then
      Console.WriteLine(negBigInt)
    Else
       Console.WriteLine("Unable to convert the string '{0}' to a BigInteger value.", _
                          negativeString)
    End If         
    ' The example displays the following output:
    '   9.1389681247993671255432112E+31
    '   -9.0315837410896312071002088037E+34
    
  • È possibile chiamare un static metodo (Shared in Visual Basic) BigInteger che esegue un'operazione su un'espressione numerica e restituisce un risultato calcolato BigInteger . L'esempio seguente esegue questa operazione cubiando UInt64.MaxValue e assegnando il risultato a un BigIntegeroggetto .

    BigInteger number = BigInteger.Pow(UInt64.MaxValue, 3);
    Console.WriteLine(number);
    // The example displays the following output:
    //    6277101735386680762814942322444851025767571854389858533375
    
    Dim number As BigInteger = BigInteger.Pow(UInt64.MaxValue, 3)
    Console.WriteLine(number)
    ' The example displays the following output:
      ' 6277101735386680762814942322444851025767571854389858533375
    

Il valore non inizializzato di un BigInteger oggetto è Zero.

Esecuzione di operazioni sui valori BigInteger

È possibile usare un'istanza BigInteger come si userebbe qualsiasi altro tipo integrale. BigInteger esegue l'overload degli operatori numerici standard per consentire di eseguire operazioni matematiche di base, ad esempio l'aggiunta, la sottrazione, la divisione, la moltiplicazione e la negazione unaria. È anche possibile usare gli operatori numerici standard per confrontare due BigInteger valori tra loro. Come gli altri tipi integrali, BigInteger supporta anche gli operatori bit per Andbit , OrXOrmaiuscole e destra. Per i linguaggi che non supportano operatori personalizzati, la struttura fornisce anche metodi equivalenti per l'esecuzione BigInteger di operazioni matematiche. Questi includono Add, , NegateDivideMultiply, Subtract, e diversi altri.

Molti membri della BigInteger struttura corrispondono direttamente ai membri degli altri tipi integrali. Inoltre, BigInteger aggiunge membri come i seguenti:

  • Sign, che restituisce un valore che indica il segno di un BigInteger valore.

  • Abs, che restituisce il valore assoluto di un BigInteger valore.

  • DivRem, che restituisce sia il quoziente che il resto di un'operazione di divisione.

  • GreatestCommonDivisor, che restituisce il più grande divisore comune di due BigInteger valori.

Molti di questi membri aggiuntivi corrispondono ai membri della Math classe, che fornisce la funzionalità per lavorare con i tipi numerici primitivi.

Mutabilità e struttura BigInteger

Nell'esempio seguente viene creata un'istanza di un BigInteger oggetto e quindi viene incrementato il relativo valore per uno.

BigInteger number = BigInteger.Multiply(Int64.MaxValue, 3);
number++;
Console.WriteLine(number);
Dim number As BigInteger = BigInteger.Multiply(Int64.MaxValue, 3)
number += 1
Console.WriteLine(number)

Anche se questo esempio viene visualizzato per modificare il valore dell'oggetto esistente, questo non è il caso. BigInteger gli oggetti non modificabili, ovvero internamente, Common Language Runtime crea effettivamente un nuovo BigInteger oggetto e lo assegna un valore maggiore del relativo valore precedente. Questo nuovo oggetto viene quindi restituito al chiamante.

Nota

Gli altri tipi numerici in .NET sono anche non modificabili. Tuttavia, poiché il tipo non ha limiti superiori o inferiori, i BigInteger relativi valori possono aumentare estremamente grandi e avere un impatto misurabile sulle prestazioni.

Anche se questo processo è trasparente per il chiamante, comporta una penalità delle prestazioni. In alcuni casi, soprattutto quando le operazioni ripetute vengono eseguite in un ciclo su valori molto grandi BigInteger , tale penalità delle prestazioni può essere significativa. Nell'esempio seguente, ad esempio, un'operazione viene eseguita in modo ripetitivo fino a un milione di volte e un BigInteger valore viene incrementato uno ogni volta che l'operazione ha esito positivo.

BigInteger number = Int64.MaxValue ^ 5;
int repetitions = 1000000;
// Perform some repetitive operation 1 million times.
for (int ctr = 0; ctr <= repetitions; ctr++)
{
   // Perform some operation. If it fails, exit the loop.
   if (! SomeOperationSucceeds()) break;
   // The following code executes if the operation succeeds.
   number++;
}
Dim number As BigInteger = Int64.MaxValue ^ 5
Dim repetitions As Integer = 1000000
' Perform some repetitive operation 1 million times.
For ctr As Integer = 0 To repetitions
   ' Perform some operation. If it fails, exit the loop.
   If Not SomeOperationSucceeds() Then Exit For
   ' The following code executes if the operation succeeds.
   number += 1
Next

In questo caso, è possibile migliorare le prestazioni eseguendo tutte le assegnazioni intermedie a una Int32 variabile. Il valore finale della variabile può quindi essere assegnato all'oggetto BigInteger quando il ciclo viene chiuso. Nell'esempio seguente viene illustrato questo concetto.

BigInteger number = Int64.MaxValue ^ 5;
int repetitions = 1000000;
int actualRepetitions = 0;
// Perform some repetitive operation 1 million times.
for (int ctr = 0; ctr <= repetitions; ctr++)
{
   // Perform some operation. If it fails, exit the loop.
   if (! SomeOperationSucceeds()) break;
   // The following code executes if the operation succeeds.
   actualRepetitions++;
}
number += actualRepetitions;
Dim number As BigInteger = Int64.MaxValue ^ 5
Dim repetitions As Integer = 1000000
Dim actualRepetitions As Integer = 0
' Perform some repetitive operation 1 million times.
For ctr As Integer = 0 To repetitions
   ' Perform some operation. If it fails, exit the loop.
   If Not SomeOperationSucceeds() Then Exit For
   ' The following code executes if the operation succeeds.
   actualRepetitions += 1
Next
number += actualRepetitions

Uso di matrici byte e stringhe esadecimali

Se si converte valori in matrici di byte o se si converte BigInteger la matrice di byte in BigInteger valori, è necessario considerare l'ordine dei byte. La BigInteger struttura prevede che i singoli byte in una matrice di byte vengano visualizzati in ordine little-endian, ovvero i byte in ordine inferiore del valore precedono i byte di ordine superiore. È possibile eseguire il round trip di un BigInteger valore chiamando il metodo e quindi passando la ToByteArray matrice di byte risultante al BigInteger(Byte[]) costruttore, come illustrato nell'esempio seguente.

BigInteger number = BigInteger.Pow(Int64.MaxValue, 2);
Console.WriteLine(number);

// Write the BigInteger value to a byte array.
byte[] bytes = number.ToByteArray();

// Display the byte array.
foreach (byte byteValue in bytes)
   Console.Write("0x{0:X2} ", byteValue);
Console.WriteLine();

// Restore the BigInteger value from a Byte array.
BigInteger newNumber = new BigInteger(bytes);
Console.WriteLine(newNumber);
// The example displays the following output:
//    8.5070591730234615847396907784E+37
//    0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x3F
//
//    8.5070591730234615847396907784E+37
Dim number As BigInteger = BigInteger.Pow(Int64.MaxValue, 2)     
Console.WriteLine(number)

' Write the BigInteger value to a byte array.
Dim bytes() As Byte = number.ToByteArray()

' Display the byte array.
For Each byteValue As Byte In bytes
   Console.Write("0x{0:X2} ", byteValue)
Next   
Console.WriteLine()

' Restore the BigInteger value from a Byte array.
Dim newNumber As BigInteger = New BigInteger(bytes)
Console.WriteLine(newNumber)               
' The example displays the following output:
'    8.5070591730234615847396907784E+37
'    0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x3F
'    
'    8.5070591730234615847396907784E+37

Per creare un'istanza di un valore da una matrice di byte che rappresenta un BigInteger valore di un altro tipo integrale, è possibile passare il valore BitConverter.GetBytes integrale al metodo e quindi passare la matrice di byte risultante al BigInteger(Byte[]) costruttore. Nell'esempio seguente viene creato un'istanza di un BigInteger valore da una matrice di byte che rappresenta un Int16 valore.

short originalValue = 30000;
Console.WriteLine(originalValue);

// Convert the Int16 value to a byte array.
byte[] bytes = BitConverter.GetBytes(originalValue);

// Display the byte array.
foreach (byte byteValue in bytes)
   Console.Write("0x{0} ", byteValue.ToString("X2"));
Console.WriteLine();

// Pass byte array to the BigInteger constructor.
BigInteger number = new BigInteger(bytes);
Console.WriteLine(number);
// The example displays the following output:
//       30000
//       0x30 0x75
//       30000
Dim originalValue As Short = 30000
Console.WriteLine(originalValue)

' Convert the Int16 value to a byte array.
Dim bytes() As Byte = BitConverter.GetBytes(originalValue)

' Display the byte array.
For Each byteValue As Byte In bytes
   Console.Write("0x{0} ", byteValue.ToString("X2"))
Next    
Console.WriteLine() 

' Pass byte array to the BigInteger constructor.
Dim number As BigInteger = New BigInteger(bytes)
Console.WriteLine(number)
' The example displays the following output:
'       30000
'       0x30 0x75
'       30000

La BigInteger struttura presuppone che i valori negativi vengano archiviati usando la rappresentazione di complemento di due. Poiché la BigInteger struttura rappresenta un valore numerico senza lunghezza fissa, il BigInteger(Byte[]) costruttore interpreta sempre il bit più significativo dell'ultimo byte nella matrice come bit di segno. Per impedire al BigInteger(Byte[]) costruttore di confondere la rappresentazione di complemento di un valore negativo con la rappresentazione di segno e grandezza di un valore positivo, valori positivi in cui il bit più significativo dell'ultimo byte nella matrice di byte dovrebbe essere normalmente impostato deve includere un byte aggiuntivo il cui valore è 0. Ad esempio, 0xC0 0xBD 0xF0 0xFF è la rappresentazione esadecimale little-endian di -1.000.000 o 4.293.967.296. Poiché il bit più significativo dell'ultimo byte in questa matrice è attivo, il valore della matrice di byte verrebbe interpretato dal BigInteger(Byte[]) costruttore come -1.000.000. Per creare un'istanza di un BigInteger valore positivo, una matrice di byte i cui elementi sono 0xC0 0xBD 0xF0 0xFF 0x00 deve essere passata al costruttore. Questa condizione è illustrata nell'esempio seguente.

int negativeNumber = -1000000;
uint positiveNumber = 4293967296;

byte[] negativeBytes = BitConverter.GetBytes(negativeNumber);
BigInteger negativeBigInt = new BigInteger(negativeBytes);
Console.WriteLine(negativeBigInt.ToString("N0"));

byte[] tempPosBytes = BitConverter.GetBytes(positiveNumber);
byte[] positiveBytes = new byte[tempPosBytes.Length + 1];
Array.Copy(tempPosBytes, positiveBytes, tempPosBytes.Length);
BigInteger positiveBigInt = new BigInteger(positiveBytes);
Console.WriteLine(positiveBigInt.ToString("N0"));
// The example displays the following output:
//    -1,000,000
//    4,293,967,296
Dim negativeNumber As Integer = -1000000
Dim positiveNumber As UInteger = 4293967296

Dim negativeBytes() As Byte = BitConverter.GetBytes(negativeNumber) 
Dim negativeBigInt As New BigInteger(negativeBytes)
Console.WriteLine(negativeBigInt.ToString("N0"))

Dim tempPosBytes() As Byte = BitConverter.GetBytes(positiveNumber)
Dim positiveBytes(tempposBytes.Length) As Byte
Array.Copy(tempPosBytes, positiveBytes, tempPosBytes.Length)
Dim positiveBigInt As New BigInteger(positiveBytes)
Console.WriteLine(positiveBigInt.ToString("N0")) 
' The example displays the following output:
'    -1,000,000
'    4,293,967,296

Le matrici di byte create dal ToByteArray metodo dai valori positivi includono questo byte di valore zero aggiuntivo. Pertanto, la struttura può eseguire correttamente il BigInteger round trip assegnandoli a e quindi ripristinandoli da matrici di byte, come illustrato nell'esempio seguente.

BigInteger positiveValue = 15777216;
BigInteger negativeValue  = -1000000;

Console.WriteLine("Positive value: " + positiveValue.ToString("N0"));
byte[] bytes = positiveValue.ToByteArray();

foreach (byte byteValue in bytes)
   Console.Write("{0:X2} ", byteValue);
Console.WriteLine();
positiveValue = new BigInteger(bytes);
Console.WriteLine("Restored positive value: " + positiveValue.ToString("N0"));

Console.WriteLine();

Console.WriteLine("Negative value: " + negativeValue.ToString("N0"));
bytes = negativeValue.ToByteArray();
foreach (byte byteValue in bytes)
   Console.Write("{0:X2} ", byteValue);
Console.WriteLine();
negativeValue = new BigInteger(bytes);
Console.WriteLine("Restored negative value: " + negativeValue.ToString("N0"));
// The example displays the following output:
//       Positive value: 15,777,216
//       C0 BD F0 00
//       Restored positive value: 15,777,216
//
//       Negative value: -1,000,000
//       C0 BD F0
//       Restored negative value: -1,000,000
Dim positiveValue As BigInteger = 15777216
Dim negativeValue As BigInteger = -1000000

Console.WriteLine("Positive value: " + positiveValue.ToString("N0"))
Dim bytes() As Byte = positiveValue.ToByteArray()
For Each byteValue As Byte In bytes
   Console.Write("{0:X2} ", byteValue)
Next
Console.WriteLine()
positiveValue = New BigInteger(bytes)
Console.WriteLine("Restored positive value: " + positiveValue.ToString("N0"))

Console.WriteLine()
   
Console.WriteLIne("Negative value: " + negativeValue.ToString("N0"))
bytes = negativeValue.ToByteArray()
For Each byteValue As Byte In bytes
   Console.Write("{0:X2} ", byteValue)
Next
Console.WriteLine()
negativeValue = New BigInteger(bytes)
Console.WriteLine("Restored negative value: " + negativeValue.ToString("N0"))
' The example displays the following output:
'       Positive value: 15,777,216
'       C0 BD F0 00
'       Restored positive value: 15,777,216
'       
'       Negative value: -1,000,000
'       C0 BD F0
'       Restored negative value: -1,000,000

Tuttavia, potrebbe essere necessario aggiungere questo byte zero aggiuntivo alle matrici di byte create dinamicamente dallo sviluppatore o restituite dai metodi che convertono interi senza segno in matrici di byte, ad esempio BitConverter.GetBytes(UInt16), BitConverter.GetBytes(UInt32)e BitConverter.GetBytes(UInt64).

Quando si analizza una stringa esadecimale, i BigInteger.Parse(String, NumberStyles) metodi e BigInteger.Parse(String, NumberStyles, IFormatProvider) presuppongono che se il bit più significativo del primo byte nella stringa è impostato o se la prima cifra esadecimale della stringa rappresenta i quattro bit inferiori di un valore di byte, il valore è rappresentato dalla rappresentazione di complemento di due. Ad esempio, sia "FF01" che "F01" rappresentano il valore decimale -255. Per distinguere i valori positivi dai valori negativi, i valori positivi devono includere uno zero iniziale. Gli overload pertinenti del metodo, quando vengono passati alla stringa di ToString formato "X", aggiungere uno zero iniziale alla stringa esadecimale restituita per i valori positivi. In questo modo è possibile eseguire il round trip BigInteger dei valori usando i ToString metodi e Parse , come illustrato nell'esempio seguente.

BigInteger negativeNumber = -1000000;
BigInteger positiveNumber  = 15777216;

string negativeHex = negativeNumber.ToString("X");
string positiveHex = positiveNumber.ToString("X");

BigInteger negativeNumber2, positiveNumber2;
negativeNumber2 = BigInteger.Parse(negativeHex,
                                   NumberStyles.HexNumber);
positiveNumber2 = BigInteger.Parse(positiveHex,
                                   NumberStyles.HexNumber);

Console.WriteLine("Converted {0:N0} to {1} back to {2:N0}.",
                   negativeNumber, negativeHex, negativeNumber2);
Console.WriteLine("Converted {0:N0} to {1} back to {2:N0}.",
                   positiveNumber, positiveHex, positiveNumber2);
// The example displays the following output:
//       Converted -1,000,000 to F0BDC0 back to -1,000,000.
//       Converted 15,777,216 to 0F0BDC0 back to 15,777,216.
Dim negativeNumber As BigInteger = -1000000
Dim positiveNumber As BigInteger = 15777216

Dim negativeHex As String = negativeNumber.ToString("X")
Dim positiveHex As string = positiveNumber.ToString("X")

Dim negativeNumber2, positiveNumber2 As BigInteger 
negativeNumber2 = BigInteger.Parse(negativeHex, 
                                   NumberStyles.HexNumber)
positiveNumber2 = BigInteger.Parse(positiveHex,
                                   NumberStyles.HexNumber)

Console.WriteLine("Converted {0:N0} to {1} back to {2:N0}.", 
                   negativeNumber, negativeHex, negativeNumber2)                                         
Console.WriteLine("Converted {0:N0} to {1} back to {2:N0}.", 
                   positiveNumber, positiveHex, positiveNumber2)                                         
' The example displays the following output:
'       Converted -1,000,000 to F0BDC0 back to -1,000,000.
'       Converted 15,777,216 to 0F0BDC0 back to 15,777,216.

Tuttavia, le stringhe esadecimali create chiamando i ToString metodi degli altri tipi integrali o gli overload del ToString metodo che includono un toBase parametro non indicano il segno del valore o il tipo di dati di origine da cui è derivata la stringa esadecimale. L'istanza di un BigInteger valore da tale stringa richiede una logica aggiuntiva. Nell'esempio seguente viene fornita una possibile implementazione.

using System;
using System.Globalization;
using System.Numerics;

public struct HexValue
{
   public int Sign;
   public string Value;
}

public class Example
{
   public static void Main()
   {
      uint positiveNumber = 4039543321;
      int negativeNumber = -255423975;

      // Convert the numbers to hex strings.
      HexValue hexValue1, hexValue2;
      hexValue1.Value = positiveNumber.ToString("X");
      hexValue1.Sign = Math.Sign(positiveNumber);

      hexValue2.Value = Convert.ToString(negativeNumber, 16);
      hexValue2.Sign = Math.Sign(negativeNumber);

      // Round-trip the hexadecimal values to BigInteger values.
      string hexString;
      BigInteger positiveBigInt, negativeBigInt;

      hexString = (hexValue1.Sign == 1 ? "0" : "") + hexValue1.Value;
      positiveBigInt = BigInteger.Parse(hexString, NumberStyles.HexNumber);
      Console.WriteLine("Converted {0} to {1} and back to {2}.",
                        positiveNumber, hexValue1.Value, positiveBigInt);

      hexString = (hexValue2.Sign == 1 ? "0" : "") + hexValue2.Value;
      negativeBigInt = BigInteger.Parse(hexString, NumberStyles.HexNumber);
      Console.WriteLine("Converted {0} to {1} and back to {2}.",
                        negativeNumber, hexValue2.Value, negativeBigInt);
   }
}
// The example displays the following output:
//       Converted 4039543321 to F0C68A19 and back to 4039543321.
//       Converted -255423975 to f0c68a19 and back to -255423975.
Imports System.Globalization
Imports System.Numerics

Public Structure HexValue
   Public Sign As Integer
   Public Value As String
End Structure
   
Module Example
   Public Sub Main()
      Dim positiveNumber As UInteger = 4039543321
      Dim negativeNumber As Integer = -255423975

      ' Convert the numbers to hex strings.
      Dim hexValue1, hexValue2 As HexValue
      hexValue1.Value = positiveNumber.ToString("X")
      hexValue1.Sign = Math.Sign(positiveNumber)
      
      hexValue2.Value = Convert.ToString(negativeNumber, 16)
      hexValue2.Sign = Math.Sign(negativeNumber)
      
      ' Round-trip the hexadecimal values to BigInteger values.
      Dim hexString As String
      Dim positiveBigInt, negativeBigInt As BigInteger
      
      hexString = CStr(IIf(hexValue1.Sign = 1, "0", "")) + hexValue1.Value
      positiveBigInt = BigInteger.Parse(hexString, NumberStyles.HexNumber)      
      Console.WriteLine("Converted {0} to {1} and back to {2}.", 
                        positiveNumber, hexValue1.Value, positiveBigInt)

      hexString = CStr(IIf(hexValue2.Sign = 1, "0", "")) + hexValue2.Value
      negativeBigInt = BigInteger.Parse(hexString, NumberStyles.HexNumber)      
      Console.WriteLine("Converted {0} to {1} and back to {2}.", 
                        negativeNumber, hexValue2.Value, negativeBigInt)

   End Sub
End Module
' The example displays the following output:
'       Converted 4039543321 to F0C68A19 and back to 4039543321.
'       Converted -255423975 to f0c68a19 and back to -255423975.

Costruttori

BigInteger(Byte[])

Inizializza una nuova istanza della struttura BigInteger utilizzando i valori di una matrice di byte.

BigInteger(Decimal)

Inizializza una nuova istanza della struttura BigInteger utilizzando un valore Decimal.

BigInteger(Double)

Inizializza una nuova istanza della struttura BigInteger utilizzando un valore a virgola mobile con precisione doppia.

BigInteger(Int32)

Inizializza una nuova istanza della struttura BigInteger utilizzando un Signed Integer a 32 bit.

BigInteger(Int64)

Inizializza una nuova istanza della struttura BigInteger usando un valore intero con segno a 64 bit.

BigInteger(ReadOnlySpan<Byte>, Boolean, Boolean)

Inizializza una nuova istanza della struttura BigInteger usando i valori in un intervallo di byte di sola lettura e indicando facoltativamente la codifica con firma e l'ordine dei byte.

BigInteger(Single)

Inizializza una nuova istanza della struttura BigInteger utilizzando un valore a virgola mobile con precisione singola.

BigInteger(UInt32)

Inizializza una nuova istanza della struttura BigInteger utilizzando un valore Unsigned Integer a 32 bit.

BigInteger(UInt64)

Inizializza una nuova istanza della struttura BigInteger con un valore Unsigned Integer a 64 bit.

Proprietà

IsEven

Indica se il valore dell'oggetto BigInteger corrente è un numero pari.

IsOne

Indica se il valore dell'oggetto BigInteger corrente è One.

IsPowerOfTwo

Indica se il valore dell'oggetto BigInteger corrente è una potenza di due.

IsZero

Indica se il valore dell'oggetto BigInteger corrente è Zero.

MinusOne

Ottiene un valore che rappresenta il numero negativo uno (-1).

One

Ottiene un valore che rappresenta il numero uno (1).

Sign

Ottiene un numero che indica il segno (negativo, positivo o zero) dell'oggetto BigInteger corrente.

Zero

Ottiene un valore che rappresenta il numero 0 (zero).

Metodi

Abs(BigInteger)

Ottiene il valore assoluto di un oggetto BigInteger.

Add(BigInteger, BigInteger)

Somma due valori BigInteger e restituisce il risultato.

Clamp(BigInteger, BigInteger, BigInteger)

Blocca un valore a un valore minimo e massimo inclusivo.

Compare(BigInteger, BigInteger)

Confronta due valori BigInteger e restituisce un Integer che indica se il primo valore è minore, uguale o maggiore rispetto al secondo valore.

CompareTo(BigInteger)

Confronta questa istanza con un secondo BigInteger e restituisce un Integer che indica se il valore di questa istanza è minore, uguale o maggiore rispetto al valore dell'oggetto specificato.

CompareTo(Int64)

Confronta questa istanza con un intero con segno a 64 bit e restituisce un intero che indica se il valore di questa istanza è minore, uguale o maggiore del valore dell'intero con segno a 64 bit.

CompareTo(Object)

Confronta questa istanza con un oggetto specificato e restituisce un intero che indica se il valore di questa istanza è minore, uguale o maggiore rispetto al valore dell'oggetto specificato.

CompareTo(UInt64)

Confronta questa istanza con un intero senza segno a 64 bit e restituisce un intero che indica se il valore di questa istanza è minore, uguale o maggiore del valore dell'intero senza segno a 64 bit.

CopySign(BigInteger, BigInteger)

Copia il segno di un valore nel segno di un altro valore.

CreateChecked<TOther>(TOther)

Crea un'istanza del tipo corrente da un valore, che genera un'eccezione di overflow per tutti i valori che non rientrano nell'intervallo rappresentabile del tipo corrente.

CreateSaturating<TOther>(TOther)

Crea un'istanza del tipo corrente da un valore, saturando tutti i valori che non rientrano nell'intervallo rappresentabile del tipo corrente.

CreateTruncating<TOther>(TOther)

Crea un'istanza del tipo corrente da un valore, troncando tutti i valori che non rientrano nell'intervallo rappresentabile del tipo corrente.

Divide(BigInteger, BigInteger)

Divide un valore BigInteger per un altro e restituisce il risultato.

DivRem(BigInteger, BigInteger)

Calcola il quoziente e il resto di due valori.

DivRem(BigInteger, BigInteger, BigInteger)

Divide un valore BigInteger per un altro, restituisce il risultato e restituisce il resto in un parametro di output.

Equals(BigInteger)

Restituisce un valore che indica se l'istanza corrente e un oggetto BigInteger specificato hanno lo stesso valore.

Equals(Int64)

Restituisce un valore che indica se l'istanza corrente e un intero con segno a 64 bit hanno lo stesso valore.

Equals(Object)

Restituisce un valore che indica se l'istanza corrente e un oggetto specificato hanno lo stesso valore.

Equals(UInt64)

Restituisce un valore che indica se l'istanza corrente e un intero senza segno a 64 bit hanno lo stesso valore.

GetBitLength()

Ottiene il numero di bit necessari per la rappresentazione del complemento a due più breve dell'istanza corrente senza il bit più significativo.

GetByteCount(Boolean)

Ottiene il numero di byte che saranno restituiti da ToByteArray(Boolean, Boolean) e TryWriteBytes(Span<Byte>, Int32, Boolean, Boolean).

GetHashCode()

Restituisce il codice hash per l'oggetto BigInteger corrente.

GreatestCommonDivisor(BigInteger, BigInteger)

Trova il massimo comune divisore di due valori BigInteger.

IsEvenInteger(BigInteger)

Determina se un valore rappresenta un numero integrale pari.

IsNegative(BigInteger)

Determina se un valore è negativo.

IsOddInteger(BigInteger)

Determina se un valore rappresenta un numero integrale dispari.

IsPositive(BigInteger)

Determina se un valore è positivo.

IsPow2(BigInteger)

Determina se un valore è una potenza di due.

LeadingZeroCount(BigInteger)

Calcola il numero di zeri iniziali in un valore.

Log(BigInteger)

Restituisce il logaritmo naturale (in base e) di un numero specificato.

Log(BigInteger, Double)

Restituisce il logaritmo del numero specificato in una base specificata.

Log10(BigInteger)

Restituisce il logaritmo in base 10 del numero specificato.

Log2(BigInteger)

Calcola il log2 di un valore.

Max(BigInteger, BigInteger)

Restituisce il maggiore di due valori BigInteger.

MaxMagnitude(BigInteger, BigInteger)

Confronta due valori con il calcolo maggiore.

Min(BigInteger, BigInteger)

Restituisce il minore di due valori BigInteger.

MinMagnitude(BigInteger, BigInteger)

Confronta due valori con il calcolo minore.

ModPow(BigInteger, BigInteger, BigInteger)

Esegue la divisione con modulo per un numero elevato alla potenza di un altro numero.

Multiply(BigInteger, BigInteger)

Restituisce il prodotto di due valori BigInteger.

Negate(BigInteger)

Nega un valore BigInteger specificato.

Parse(ReadOnlySpan<Char>, IFormatProvider)

Analizza un intervallo di caratteri in un valore.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Converte la rappresentazione di un numero, contenuto nell'intervallo di caratteri di sola lettura specificato, in uno stile specificato nell'equivalente BigInteger.

Parse(String)

Converte la rappresentazione di stringa di un numero nell'oggetto BigInteger equivalente.

Parse(String, IFormatProvider)

Converte la rappresentazione di stringa di un numero in un formato specifico delle impostazioni cultura indicato nell'oggetto BigInteger equivalente.

Parse(String, NumberStyles)

Converte la rappresentazione di stringa di un numero in uno stile specificato nell'oggetto BigInteger equivalente.

Parse(String, NumberStyles, IFormatProvider)

Converte la rappresentazione di stringa di un numero in uno stile specificato e un formato specifico delle impostazioni cultura indicato nell'oggetto BigInteger equivalente.

PopCount(BigInteger)

Calcola il numero di bit impostati in un valore.

Pow(BigInteger, Int32)

Eleva alla potenza di un valore specificato il valore BigInteger.

Remainder(BigInteger, BigInteger)

Esegue una divisione intera su due valori BigInteger e restituisce il resto.

RotateLeft(BigInteger, Int32)

Ruota un valore sinistro da una determinata quantità.

RotateRight(BigInteger, Int32)

Ruota un valore a destra in base a una determinata quantità.

Subtract(BigInteger, BigInteger)

Sottrae un valore BigInteger da un altro e restituisce il risultato.

ToByteArray()

Converte un valore BigInteger in una matrice di byte.

ToByteArray(Boolean, Boolean)

Restituisce il valore di BigInteger come matrice di byte usando il minor numero possibile di byte. Se il valore è zero, restituisce una matrice di un byte il cui elemento è 0x00.

ToString()

Converte il valore numerico dell'oggetto BigInteger corrente nella rappresentazione di stringa equivalente.

ToString(IFormatProvider)

Converte il valore numerico dell'oggetto BigInteger corrente nella rappresentazione di stringa equivalente usando le informazioni di formattazione specifiche delle impostazioni cultura indicate.

ToString(String)

Converte il valore numerico dell'oggetto BigInteger corrente nella rappresentazione di stringa equivalente, usando il formato specificato.

ToString(String, IFormatProvider)

Converte il valore numerico dell'oggetto BigInteger corrente nella rappresentazione di stringa equivalente usando il formato specificato e le informazioni di formattazione specifiche delle impostazioni cultura indicate.

TrailingZeroCount(BigInteger)

Calcola il numero di zero finali in un valore.

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

Formatta questa istanza di big integer in un intervallo di caratteri.

TryParse(ReadOnlySpan<Char>, BigInteger)

Prova a convertire la rappresentazione di un numero contenuto nell'intervallo di caratteri di sola lettura specificato nell'oggetto BigInteger equivalente e restituisce un valore che indica se la conversione è stata eseguita correttamente.

TryParse(ReadOnlySpan<Char>, IFormatProvider, BigInteger)

Prova a analizzare un intervallo di caratteri in un valore.

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger)

Prova a convertire la rappresentazione di stringa di un numero nell'oggetto BigInteger equivalente e restituisce un valore che indica se la conversione è stata eseguita correttamente.

TryParse(String, BigInteger)

Prova a convertire la rappresentazione di stringa di un numero nell'oggetto BigInteger equivalente e restituisce un valore che indica se la conversione è stata eseguita correttamente.

TryParse(String, IFormatProvider, BigInteger)

Prova a analizzare una stringa in un valore.

TryParse(String, NumberStyles, IFormatProvider, BigInteger)

Prova a convertire la rappresentazione di stringa di un numero in uno stile specificato e un formato specifico delle impostazioni cultura indicato nell'oggetto BigInteger equivalente e restituisce un valore che indica se la conversione è stata eseguita correttamente.

TryWriteBytes(Span<Byte>, Int32, Boolean, Boolean)

Copia il valore di BigInteger come byte di complemento a due little endian usando il minor numero possibile di byte. Se il valore è zero, restituisce un byte il cui elemento è 0x00.

Operatori

Addition(BigInteger, BigInteger)

Somma i valori di due oggetti BigInteger specificati.

BitwiseAnd(BigInteger, BigInteger)

Esegue un'operazione And bit per bit su due valori BigInteger.

BitwiseOr(BigInteger, BigInteger)

Esegue un'operazione Or bit per bit su due valori BigInteger.

Decrement(BigInteger)

Decrementa un valore BigInteger di 1.

Division(BigInteger, BigInteger)

Divide un valore BigInteger specificato per un altro valore BigInteger specificato tramite una divisione intera.

Equality(BigInteger, BigInteger)

Restituisce un valore che indica se i valori di due oggetti BigInteger sono uguali.

Equality(BigInteger, Int64)

Restituisce un valore che indica se un valore Signed Long Integer e un valore BigInteger sono uguali.

Equality(BigInteger, UInt64)

Restituisce un valore che indica se un valore Unsigned Long Integer e un valore BigInteger sono uguali.

Equality(Int64, BigInteger)

Restituisce un valore che indica se un valore Signed Long Integer e un valore BigInteger sono uguali.

Equality(UInt64, BigInteger)

Restituisce un valore che indica se un valore Unsigned Long Integer e un valore BigInteger sono uguali.

ExclusiveOr(BigInteger, BigInteger)

Esegue un'operazione Or (XOr) bit per bit esclusiva su due valori BigInteger.

Explicit(BigInteger to Byte)

Definisce una conversione esplicita di un oggetto BigInteger in un valore byte senza segno.

Explicit(BigInteger to Char)

Converte in modo esplicito un numero intero grande in un Char valore.

Explicit(BigInteger to Decimal)

Definisce una conversione esplicita di un oggetto BigInteger in un valore Decimal.

Explicit(BigInteger to Double)

Definisce una conversione esplicita di un oggetto BigInteger in un valore Double.

Explicit(BigInteger to Half)

Converte in modo esplicito un numero intero grande in un Half valore.

Explicit(BigInteger to Int128)

Converte in modo esplicito un numero intero grande in un Int128 valore.

Explicit(BigInteger to Int16)

Definisce una conversione esplicita di un oggetto BigInteger in un valore Signed Integer a 16 bit.

Explicit(BigInteger to Int32)

Definisce una conversione esplicita di un oggetto BigInteger in un valore intero con segno a 32 bit.

Explicit(BigInteger to Int64)

Definisce una conversione esplicita di un oggetto BigInteger in un valore intero con segno a 64 bit.

Explicit(BigInteger to IntPtr)

Converte in modo esplicito un numero intero grande in un IntPtr valore.

Explicit(BigInteger to SByte)

Definisce una conversione esplicita di un oggetto BigInteger in un valore a 8 bit con segno.

Questa API non è conforme a CLS. L'alternativa conforme è Int16.

Explicit(BigInteger to Single)

Definisce una conversione esplicita di un oggetto BigInteger in un valore in virgola mobile a precisione singola.

Explicit(BigInteger to UInt128)

Converte in modo esplicito un numero intero grande in un UInt128 valore.

Explicit(BigInteger to UInt16)

Definisce una conversione esplicita di un oggetto BigInteger in un valore Unsigned Integer a 16 bit.

Questa API non è conforme a CLS. L'alternativa conforme è Int32.

Explicit(BigInteger to UInt32)

Definisce una conversione esplicita di un oggetto BigInteger in un valore intero senza segno a 32 bit.

Questa API non è conforme a CLS. L'alternativa conforme è Int64.

Explicit(BigInteger to UInt64)

Definisce una conversione esplicita di un oggetto BigInteger in un valore intero senza segno a 64 bit.

Questa API non è conforme a CLS. L'alternativa conforme è Double.

Explicit(BigInteger to UIntPtr)

Converte in modo esplicito un numero intero grande in un UIntPtr valore.

Explicit(Complex to BigInteger)

Converte in modo esplicito un Complex valore in un numero intero grande.

Explicit(Decimal to BigInteger)

Definisce una conversione esplicita di un oggetto Decimal in un valore BigInteger.

Explicit(Double to BigInteger)

Definisce una conversione esplicita di un valore Double in un valore BigInteger.

Explicit(Half to BigInteger)

Converte in modo esplicito un Half valore in un numero intero grande.

Explicit(Single to BigInteger)

Definisce una conversione esplicita di un valore Single in un valore BigInteger.

GreaterThan(BigInteger, BigInteger)

Restituisce un valore che indica se un valore BigInteger è maggiore di un altro valore BigInteger.

GreaterThan(BigInteger, Int64)

Restituisce un valore che indica se un BigInteger è maggiore di un valore Signed Integer a 64 bit.

GreaterThan(BigInteger, UInt64)

Restituisce un valore che indica se un valore BigInteger è maggiore di un Unsigned Integer a 64 bit.

GreaterThan(Int64, BigInteger)

Restituisce un valore che indica se un Signed Integer a 64 bit è maggiore di un valore BigInteger.

GreaterThan(UInt64, BigInteger)

Restituisce un valore che indica se un valore BigInteger è maggiore di un Unsigned Integer a 64 bit.

GreaterThanOrEqual(BigInteger, BigInteger)

Restituisce un valore che indica se un valore BigInteger è maggiore o uguale a un altro valore BigInteger.

GreaterThanOrEqual(BigInteger, Int64)

Restituisce un valore che indica se un valore BigInteger è maggiore o uguale a un valore Signed Integer a 64 bit.

GreaterThanOrEqual(BigInteger, UInt64)

Restituisce un valore che indica se un valore BigInteger è maggiore o uguale a un valore Unsigned Integer a 64 bit.

GreaterThanOrEqual(Int64, BigInteger)

Restituisce un valore che indica se un Signed Integer a 64 bit è maggiore o uguale a un valore BigInteger.

GreaterThanOrEqual(UInt64, BigInteger)

Restituisce un valore che indica se un Unsigned Integer a 64 bit è maggiore o uguale a un valore BigInteger.

Implicit(Byte to BigInteger)

Definisce una conversione implicita di un byte senza segno in un valore BigInteger.

Implicit(Char to BigInteger)

Converte in modo implicito un Char valore in un intero grande.

Implicit(Int128 to BigInteger)

Converte in modo implicito un Int128 valore in un intero grande.

Implicit(Int16 to BigInteger)

Definisce una conversione implicita di un Signed Integer a 16 bit in un valore BigInteger.

Implicit(Int32 to BigInteger)

Definisce una conversione implicita di un intero con segno a 32 bit in un valore BigInteger.

Implicit(Int64 to BigInteger)

Definisce una conversione implicita di un intero con segno a 64 bit in un valore BigInteger.

Implicit(IntPtr to BigInteger)

Converte in modo implicito un IntPtr valore in un intero grande.

Implicit(SByte to BigInteger)

Definisce una conversione implicita di un Signed Integer a 8 bit in un valore BigInteger.

Questa API non è conforme a CLS. L'alternativa conforme è BigInteger(Int32).

Implicit(UInt128 to BigInteger)

Converte in modo implicito un UInt128 valore in un intero grande.

Implicit(UInt16 to BigInteger)

Definisce una conversione implicita di un Unsigned Integer a 16 bit in un valore BigInteger.

Questa API non è conforme a CLS. L'alternativa conforme è Implicit(Int32 to BigInteger).

Implicit(UInt32 to BigInteger)

Definisce una conversione implicita di un intero senza segno a 32 bit in un valore BigInteger.

Questa API non è conforme a CLS. L'alternativa conforme è Implicit(Int64 to BigInteger).

Implicit(UInt64 to BigInteger)

Definisce una conversione implicita di un intero senza segno a 64 bit in un valore BigInteger.

Questa API non è conforme a CLS. L'alternativa conforme è Double.

Implicit(UIntPtr to BigInteger)

Converte in modo implicito un UIntPtr valore in un intero grande.

Increment(BigInteger)

Incrementa un valore BigInteger di 1.

Inequality(BigInteger, BigInteger)

Restituisce un valore che indica se due oggetti BigInteger hanno valori diversi.

Inequality(BigInteger, Int64)

Restituisce un valore che indica se un valore BigInteger e un Signed Integer a 64 bit non sono uguali.

Inequality(BigInteger, UInt64)

Restituisce un valore che indica se un valore BigInteger e un Unsigned Integer a 64 bit non sono uguali.

Inequality(Int64, BigInteger)

Restituisce un valore che indica se un Signed Integer a 64 bit e un valore BigInteger non sono uguali.

Inequality(UInt64, BigInteger)

Restituisce un valore che indica se un Unsigned Integer a 64 bit e un valore BigInteger non sono uguali.

LeftShift(BigInteger, Int32)

Sposta un valore BigInteger di un numero specificato di bit verso sinistra.

LessThan(BigInteger, BigInteger)

Restituisce un valore che indica se un valore BigInteger è minore di un altro valore BigInteger.

LessThan(BigInteger, Int64)

Restituisce un valore che indica se un valore BigInteger è minore di un Signed Integer a 64 bit.

LessThan(BigInteger, UInt64)

Restituisce un valore che indica se un valore BigInteger è minore di un Unsigned Integer a 64 bit.

LessThan(Int64, BigInteger)

Restituisce un valore che indica se un Signed Integer a 64 bit è minore di un valore BigInteger.

LessThan(UInt64, BigInteger)

Restituisce un valore che indica se un Unsigned Integer a 64 bit è minore di un valore BigInteger.

LessThanOrEqual(BigInteger, BigInteger)

Restituisce un valore che indica se un valore BigInteger è minore o uguale a un altro valore BigInteger.

LessThanOrEqual(BigInteger, Int64)

Restituisce un valore che indica se un valore BigInteger è minore o uguale a un Signed Integer a 64 bit.

LessThanOrEqual(BigInteger, UInt64)

Restituisce un valore che indica se un valore BigInteger è minore o uguale a un Unsigned Integer a 64 bit.

LessThanOrEqual(Int64, BigInteger)

Restituisce un valore che indica se un Signed Integer a 64 bit è minore o uguale a un valore BigInteger.

LessThanOrEqual(UInt64, BigInteger)

Restituisce un valore che indica se un Unsigned Integer a 64 bit è minore o uguale a un valore BigInteger.

Modulus(BigInteger, BigInteger)

Restituisce il resto risultante dalla divisione di due valori BigInteger specificati.

Multiply(BigInteger, BigInteger)

Moltiplica due valori BigInteger specificati.

OnesComplement(BigInteger)

Restituisce il complemento a uno bit per bit di un valore BigInteger.

RightShift(BigInteger, Int32)

Sposta un valore BigInteger di un numero specificato di bit verso destra.

Subtraction(BigInteger, BigInteger)

Sottrae un valore BigInteger da un altro valore BigInteger.

UnaryNegation(BigInteger)

Nega un valore BigInteger specificato.

UnaryPlus(BigInteger)

Restituisce il valore dell'operando BigInteger. Il segno dell'operando resta invariato.

UnsignedRightShift(BigInteger, Int32)

Sposta un valore a destra in base a una determinata quantità.

Implementazioni dell'interfaccia esplicita

IAdditiveIdentity<BigInteger,BigInteger>.AdditiveIdentity

Ottiene l'identità additiva del tipo corrente.

IBinaryInteger<BigInteger>.GetByteCount()

Ottiene il numero di byte che verranno scritti come parte di TryWriteLittleEndian(Span<Byte>, Int32).

IBinaryInteger<BigInteger>.GetShortestBitLength()

Ottiene la lunghezza, in bit, della rappresentazione di complemento più breve del valore corrente.

IBinaryInteger<BigInteger>.TryReadBigEndian(ReadOnlySpan<Byte>, Boolean, BigInteger)

Rappresenta un intero con segno arbitrariamente grande.

IBinaryInteger<BigInteger>.TryReadLittleEndian(ReadOnlySpan<Byte>, Boolean, BigInteger)

Rappresenta un intero con segno arbitrariamente grande.

IBinaryInteger<BigInteger>.TryWriteBigEndian(Span<Byte>, Int32)

Prova a scrivere il valore corrente, in formato big-endian, in un determinato intervallo.

IBinaryInteger<BigInteger>.TryWriteLittleEndian(Span<Byte>, Int32)

Tenta di scrivere il valore corrente, in formato little-endian, in un determinato intervallo.

IBinaryNumber<BigInteger>.AllBitsSet

Ottiene un'istanza del tipo binario in cui vengono impostati tutti i bit.

IComparable.CompareTo(Object)

Confronta questa istanza con un oggetto specificato e restituisce un intero che indica se il valore di questa istanza è minore, uguale o maggiore rispetto al valore dell'oggetto specificato.

IMultiplicativeIdentity<BigInteger,BigInteger>.MultiplicativeIdentity

Ottiene l'identità moltiplicativa del tipo corrente.

INumber<BigInteger>.MaxNumber(BigInteger, BigInteger)

Confronta due valori per calcolare che è maggiore e restituisce l'altro valore se un input è NaN.

INumber<BigInteger>.MinNumber(BigInteger, BigInteger)

Confronta due valori per calcolare che è minore e restituisce l'altro valore se un input è NaN.

INumber<BigInteger>.Sign(BigInteger)

Calcola il segno di un valore.

INumberBase<BigInteger>.IsCanonical(BigInteger)

Determina se un valore è nella relativa rappresentazione canonica.

INumberBase<BigInteger>.IsComplexNumber(BigInteger)

Determina se un valore rappresenta un numero complesso.

INumberBase<BigInteger>.IsFinite(BigInteger)

Determina se un valore è finito.

INumberBase<BigInteger>.IsImaginaryNumber(BigInteger)

Determina se un valore rappresenta un numero immaginario puro.

INumberBase<BigInteger>.IsInfinity(BigInteger)

Determina se un valore è infinito.

INumberBase<BigInteger>.IsInteger(BigInteger)

Determina se un valore rappresenta un numero integrale.

INumberBase<BigInteger>.IsNaN(BigInteger)

Determina se un valore è NaN.

INumberBase<BigInteger>.IsNegativeInfinity(BigInteger)

Determina se un valore è infinito negativo.

INumberBase<BigInteger>.IsNormal(BigInteger)

Determina se un valore è normale.

INumberBase<BigInteger>.IsPositiveInfinity(BigInteger)

Determina se un valore è infinito positivo.

INumberBase<BigInteger>.IsRealNumber(BigInteger)

Determina se un valore rappresenta un numero reale.

INumberBase<BigInteger>.IsSubnormal(BigInteger)

Determina se un valore è subnormal.

INumberBase<BigInteger>.IsZero(BigInteger)

Determina se un valore è zero.

INumberBase<BigInteger>.MaxMagnitudeNumber(BigInteger, BigInteger)

Confronta due valori per calcolare che ha la grandezza maggiore e restituisce l'altro valore se un input è NaN.

INumberBase<BigInteger>.MinMagnitudeNumber(BigInteger, BigInteger)

Confronta due valori per calcolare che ha la grandezza minore e restituisce l'altro valore se un input è NaN.

INumberBase<BigInteger>.Radix

Ottiene il radix o la base per il tipo.

INumberBase<BigInteger>.TryConvertFromChecked<TOther>(TOther, BigInteger)

Rappresenta un intero con segno arbitrariamente grande.

INumberBase<BigInteger>.TryConvertFromSaturating<TOther>(TOther, BigInteger)

Rappresenta un intero con segno arbitrariamente grande.

INumberBase<BigInteger>.TryConvertFromTruncating<TOther>(TOther, BigInteger)

Rappresenta un intero con segno arbitrariamente grande.

INumberBase<BigInteger>.TryConvertToChecked<TOther>(BigInteger, TOther)

Tenta di convertire un'istanza del tipo corrente in un altro tipo, generando un'eccezione di overflow per tutti i valori che rientrano all'esterno dell'intervallo rappresentabile del tipo corrente.

INumberBase<BigInteger>.TryConvertToSaturating<TOther>(BigInteger, TOther)

Tenta di convertire un'istanza del tipo corrente in un altro tipo, saturazione di tutti i valori che rientrano all'esterno dell'intervallo rappresentabile del tipo corrente.

INumberBase<BigInteger>.TryConvertToTruncating<TOther>(BigInteger, TOther)

Prova a convertire un'istanza del tipo corrente in un altro tipo, troncando tutti i valori che rientrano all'esterno dell'intervallo rappresentabile del tipo corrente.

ISignedNumber<BigInteger>.NegativeOne

Ottiene il valore -1 per il tipo.

Si applica a