BigInteger Costruttori

Definizione

Inizializza una nuova istanza della struttura BigInteger.

Overload

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(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.

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(Byte[])

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Importante

Questa API non è conforme a CLS.

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

public:
 BigInteger(cli::array <System::Byte> ^ value);
[System.CLSCompliant(false)]
public BigInteger (byte[] value);
[<System.CLSCompliant(false)>]
new System.Numerics.BigInteger : byte[] -> System.Numerics.BigInteger
Public Sub New (value As Byte())

Parametri

value
Byte[]

Matrice di valori byte in ordine little-endian.

Attributi

Eccezioni

value è null.

Esempio

Nell'esempio seguente viene creata un'istanza di un BigInteger oggetto da una matrice di byte a 5 elementi il cui valore è {5, 4, 3, 2, 1}. Visualizza quindi il BigInteger valore, rappresentato sia come numeri decimali che esadecimali, nella console. Un confronto della matrice di input con l'output di testo rende chiaro perché questo overload del BigInteger costruttore della classe crea un BigInteger oggetto il cui valore è 4328719365 (o 0x102030405). Il primo elemento della matrice di byte, il cui valore è 5, definisce il valore del byte più basso dell'oggetto BigInteger , che è 0x05. Il secondo elemento della matrice di byte, il cui valore è 4, definisce il valore del secondo byte dell'oggetto BigInteger , che è 0x04 e così via.

byte[] bytes = { 5, 4, 3, 2, 1 };
BigInteger number = new BigInteger(bytes);
Console.WriteLine("The value of number is {0} (or 0x{0:x}).", number);
// The example displays the following output:
//    The value of number is 4328719365 (or 0x102030405).
Dim bytes() As Byte = { 5, 4, 3, 2, 1 }
Dim number As New BigInteger(bytes)
Console.WriteLine("The value of number is {0} (or 0x{0:x}).", number) 
' The example displays the following output:
'    The value of number is 4328719365 (or 0x102030405).

L'esempio ToByteArray seguente crea un'istanza di un valore positivo e negativoBigInteger, li passa al metodo e quindi ripristina i valori originali BigInteger dalla matrice di byte risultante. Si noti che i due valori sono rappresentati da matrici di byte identiche. L'unica differenza tra di esse è nel bit più significativo dell'ultimo elemento nella matrice di byte. Questo bit viene impostato (il valore del byte è 0xFF) se la matrice viene creata da un valore negativo BigInteger . Il bit non è impostato (il valore del byte è zero), se la matrice viene creata da un valore positivo BigInteger .

// Instantiate BigInteger values.
BigInteger positiveValue = BigInteger.Parse("4713143110832790377889");
BigInteger negativeValue = BigInteger.Add(-Int64.MaxValue, -60000);
BigInteger positiveValue2, negativeValue2;

// Create two byte arrays.
byte[] positiveBytes = positiveValue.ToByteArray();
byte[] negativeBytes = negativeValue.ToByteArray();

// Instantiate new BigInteger from negativeBytes array.
Console.Write("Converted {0:N0} to the byte array ", negativeValue);
foreach (byte byteValue in negativeBytes)
   Console.Write("{0:X2} ", byteValue);
Console.WriteLine();
negativeValue2 = new BigInteger(negativeBytes);
Console.WriteLine("Converted the byte array to {0:N0}", negativeValue2);
Console.WriteLine();

// Instantiate new BigInteger from positiveBytes array.
Console.Write("Converted {0:N0} to the byte array ", positiveValue);
foreach (byte byteValue in positiveBytes)
   Console.Write("{0:X2} ", byteValue);
Console.WriteLine();
positiveValue2 = new BigInteger(positiveBytes);
Console.WriteLine("Converted the byte array to {0:N0}", positiveValue2);
Console.WriteLine();
// The example displays the following output:
//    Converted -9,223,372,036,854,835,807 to the byte array A1 15 FF FF FF FF FF 7F FF
//    Converted the byte array to -9,223,372,036,854,835,807
//
//    Converted 4,713,143,110,832,790,377,889 to the byte array A1 15 FF FF FF FF FF 7F FF 00
//    Converted the byte array to 4,713,143,110,832,790,377,889
' Instantiate BigInteger values.
Dim positiveValue As BigInteger = BigInteger.Parse("4713143110832790377889")
Dim negativeValue As BigInteger = BigInteger.Add(-Int64.MaxValue, -60000) 
Dim positiveValue2, negativeValue2 As BigInteger

' Create two byte arrays.
Dim positiveBytes() As Byte = positiveValue.ToByteArray()
Dim negativeBytes() As Byte = negativeValue.ToByteArray()

' Instantiate new BigInteger from negativeBytes array.
Console.Write("Converted {0:N0} to the byte array ", negativeValue)
For Each byteValue As Byte In negativeBytes
   Console.Write("{0:X2} ", byteValue)
Next 
Console.WriteLine()
negativeValue2 = New BigInteger(negativeBytes)
Console.WriteLine("Converted the byte array to {0:N0}", negativeValue2)
Console.WriteLine()

' Instantiate new BigInteger from positiveBytes array.
Console.Write("Converted {0:N0} to the byte array ", positiveValue)
For Each byteValue As Byte In positiveBytes
   Console.Write("{0:X2} ", byteValue)
Next 
Console.WriteLine()
positiveValue2 = New BigInteger(positiveBytes)
Console.WriteLine("Converted the byte array to {0:N0}", positiveValue2)
Console.WriteLine()
' The example displays the following output:
'    Converted -9,223,372,036,854,835,807 to the byte array A1 15 FF FF FF FF FF 7F FF
'    Converted the byte array to -9,223,372,036,854,835,807
'    
'    Converted 4,713,143,110,832,790,377,889 to the byte array A1 15 FF FF FF FF FF 7F FF 00
'    Converted the byte array to 4,713,143,110,832,790,377,889

Nell'esempio seguente viene illustrato come assicurarsi che un valore positivo non venga creato in modo errato come valore negativo aggiungendo un byte il cui valore è zero alla fine della matrice.

ulong originalNumber = UInt64.MaxValue;
byte[] bytes = BitConverter.GetBytes(originalNumber);
if (originalNumber > 0 && (bytes[bytes.Length - 1] & 0x80) > 0)
{
   byte[] temp = new byte[bytes.Length];
   Array.Copy(bytes, temp, bytes.Length);
   bytes = new byte[temp.Length + 1];
   Array.Copy(temp, bytes, temp.Length);
}

BigInteger newNumber = new BigInteger(bytes);
Console.WriteLine("Converted the UInt64 value {0:N0} to {1:N0}.",
                  originalNumber, newNumber);
// The example displays the following output:
//    Converted the UInt64 value 18,446,744,073,709,551,615 to 18,446,744,073,709,551,615.
Dim originalNumber As ULong = UInt64.MaxValue
' Convert an unsigned integer to a byte array.
Dim bytes() As Byte = BitConverter.GetBytes(originalNumber)
' Determine whether the MSB of the highest-order byte is set.
If originalNumber > 0 And (bytes(bytes.Length - 1) And &h80) > 0 Then
   ' If the MSB is set, add one zero-value byte to the end of the array.
   ReDim Preserve bytes(bytes.Length)
End If

Dim newNumber As New BigInteger(bytes)
Console.WriteLine("Converted the UInt64 value {0:N0} to {1:N0}.", 
                  originalNumber, newNumber) 
' The example displays the following output:
'    Converted the UInt64 value 18,446,744,073,709,551,615 to 18,446,744,073,709,551,615.

Commenti

I singoli byte nella value matrice devono essere in ordine piccolo-endiano, da byte più basso a byte più alto. Ad esempio, il valore numerico 1.000.000.000.000 è rappresentato come illustrato nella tabella seguente:

Stringa esadecimale E8D4A51000
Matrice di byte (indice più basso) 00 10 A5 D4 E8 00

La maggior parte dei metodi che converte i valori numerici in matrici di byte, ad esempio BigInteger.ToByteArray e BitConverter.GetBytes, restituisce matrici di byte in ordine little-endian.

Il costruttore prevede valori positivi nella matrice di byte di usare la rappresentazione di segno e grandezza e i valori negativi per usare la rappresentazione di complemento di due. In altre parole, se viene impostato il bit più alto del byte value più alto, il valore risultante BigInteger è negativo. A seconda dell'origine della matrice di byte, questo può causare un valore positivo non interpretato come valore negativo. Le matrici di byte vengono in genere generate nei modi seguenti:

  • Chiamando il BigInteger.ToByteArray metodo . Poiché questo metodo restituisce una matrice di byte con il bit di ordine più alto del byte più alto nella matrice impostata su zero per i valori positivi, non è possibile configurare un valore positivo come negativo. Matrici di byte non modificate create dal ToByteArray metodo sempre correttamente round trip quando vengono passate al BigInteger(Byte[]) costruttore.

  • Chiamando il BitConverter.GetBytes metodo e passandolo come parametro un intero con segno. Poiché i numeri interi firmati gestiscono sia la rappresentazione di segno che la grandezza e la rappresentazione di complemento di due, non è possibile intersecare un valore positivo come negativo.

  • Chiamando il BitConverter.GetBytes metodo e passandolo un intero senza segno come parametro. Poiché i valori interi senza segno sono rappresentati solo dalla loro grandezza, i valori positivi possono essere interpretati erroneamente come valori negativi. Per evitare questa mancata interpretazione, è possibile aggiungere un valore zero-byte alla fine della matrice. L'esempio nella sezione successiva fornisce un'illustrazione.

  • Creando una matrice di byte in modo dinamico o statico senza necessariamente chiamare uno dei metodi precedenti o modificando una matrice di byte esistente. Per impedire che i valori positivi vengano interpretati erroneamente come valori negativi, è possibile aggiungere un valore zero-byte alla fine della matrice.

Se value è una matrice vuota Byte , il nuovo BigInteger oggetto viene inizializzato in un valore di BigInteger.Zero. Se value è null, il costruttore genera un ArgumentNullExceptionoggetto .

Vedi anche

Si applica a

BigInteger(Decimal)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

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

public:
 BigInteger(System::Decimal value);
public BigInteger (decimal value);
new System.Numerics.BigInteger : decimal -> System.Numerics.BigInteger
Public Sub New (value As Decimal)

Parametri

value
Decimal

Numero decimale.

Esempio

Nell'esempio seguente viene illustrato l'uso del costruttore per creare un'istanza BigInteger(Decimal) di un BigInteger oggetto. Definisce una matrice di Decimal valori e quindi passa ogni valore al BigInteger(Decimal) costruttore. Si noti che il Decimal valore viene troncato anziché arrotondato quando viene assegnato all'oggetto BigInteger .

decimal[] decimalValues = { -1790.533m, -15.1514m, 18903.79m, 9180098.003m };
foreach (decimal decimalValue in decimalValues)
{
   BigInteger number = new BigInteger(decimalValue);
   Console.WriteLine("Instantiated BigInteger value {0} from the Decimal value {1}.",
                     number, decimalValue);
}
// The example displays the following output:
//    Instantiated BigInteger value -1790 from the Decimal value -1790.533.
//    Instantiated BigInteger value -15 from the Decimal value -15.1514.
//    Instantiated BigInteger value 18903 from the Decimal value 18903.79.
//    Instantiated BigInteger value 9180098 from the Decimal value 9180098.003.
Dim decimalValues() As Decimal = { -1790.533d, -15.1514d, 18903.79d, 9180098.003d }
For Each decimalValue As Decimal In decimalValues
   Dim number As New BigInteger(decimalValue)
   Console.WriteLine("Instantiated BigInteger value {0} from the Decimal value {1}.",
                     number, decimalValue)
Next                 
' The example displays the following output:
'    Instantiated BigInteger value -1790 from the Decimal value -1790.533.
'    Instantiated BigInteger value -15 from the Decimal value -15.1514.
'    Instantiated BigInteger value 18903 from the Decimal value 18903.79.
'    Instantiated BigInteger value 9180098 from the Decimal value 9180098.003.

Commenti

Il risultato della chiamata a questo costruttore è identico all'assegnazione esplicita di un Decimal valore a una BigInteger variabile.

La chiamata a questo costruttore può causare la perdita di dati; qualsiasi parte frazionaria di viene troncata quando si crea un'istanza di value un BigInteger oggetto.

Si applica a

BigInteger(Double)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

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

public:
 BigInteger(double value);
public BigInteger (double value);
new System.Numerics.BigInteger : double -> System.Numerics.BigInteger
Public Sub New (value As Double)

Parametri

value
Double

Valore a virgola mobile e precisione doppia.

Eccezioni

Esempio

Nell'esempio seguente viene illustrato l'uso del costruttore per creare un'istanza BigInteger(Double) di un BigInteger oggetto. Illustra anche la perdita di precisione che può verificarsi quando si usa il Double tipo di dati. Viene Double assegnato un valore di grandi dimensioni, che viene quindi assegnato a un BigInteger oggetto. Come illustrato dall'output, questa assegnazione comporta una perdita di precisione. Entrambi i valori vengono quindi incrementati di uno. L'output mostra che l'oggetto riflette il BigInteger valore modificato, mentre l'oggetto Double non è.

// Create a BigInteger from a large double value.
double doubleValue = -6e20;
BigInteger bigIntValue = new BigInteger(doubleValue);
Console.WriteLine("Original Double value: {0:N0}", doubleValue);
Console.WriteLine("Original BigInteger value: {0:N0}", bigIntValue);
// Increment and then display both values.
doubleValue++;
bigIntValue += BigInteger.One;
Console.WriteLine("Incremented Double value: {0:N0}", doubleValue);
Console.WriteLine("Incremented BigInteger value: {0:N0}", bigIntValue);
// The example displays the following output:
//    Original Double value: -600,000,000,000,000,000,000
//    Original BigInteger value: -600,000,000,000,000,000,000
//    Incremented Double value: -600,000,000,000,000,000,000
//    Incremented BigInteger value: -599,999,999,999,999,999,999
' Create a BigInteger from a large double value.
Dim doubleValue As Double = -6e20
Dim bigIntValue As New BigInteger(doubleValue)
Console.WriteLine("Original Double value: {0:N0}", doubleValue)
Console.WriteLine("Original BigInteger value: {0:N0}", bigIntValue)
' Increment and then display both values.
doubleValue += 1
bigIntValue += BigInteger.One
Console.WriteLine("Incremented Double value: {0:N0}", doubleValue)
Console.WriteLine("Incremented BigInteger value: {0:N0}", bigIntValue)
' The example displays the following output:
'    Original Double value: -600,000,000,000,000,000,000
'    Original BigInteger value: -600,000,000,000,000,000,000
'    Incremented Double value: -600,000,000,000,000,000,000
'    Incremented BigInteger value: -599,999,999,999,999,999,999

Commenti

Qualsiasi parte frazionaria del parametro viene troncata quando si crea un'istanza value di un BigInteger oggetto.

A causa della mancanza di precisione del Double tipo di dati, la chiamata a questo costruttore può causare la perdita di dati.

Il BigInteger valore risultante dalla chiamata a questo costruttore è identico al valore che determina l'assegnazione esplicita di un Double valore a un BigIntegeroggetto .

Si applica a

BigInteger(Int32)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

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

public:
 BigInteger(int value);
public BigInteger (int value);
new System.Numerics.BigInteger : int -> System.Numerics.BigInteger
Public Sub New (value As Integer)

Parametri

value
Int32

Intero con segno a 32 bit.

Esempio

Nell'esempio seguente viene chiamato il costruttore per creare BigInteger un'istanza BigInteger(Int32) di valori da una matrice di numeri interi a 32 bit. Usa anche la conversione implicita per assegnare ogni valore intero a 32 bit a una BigInteger variabile. Confronta quindi i due valori per stabilire che i valori risultanti BigInteger sono uguali.

int[] integers = { Int32.MinValue, -10534, -189, 0, 17, 113439,
                   Int32.MaxValue };
BigInteger constructed, assigned;

foreach (int number in integers)
{
   constructed = new BigInteger(number);
   assigned = number;
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned,
                     constructed.Equals(assigned));
}
// The example displays the following output:
//       -2147483648 = -2147483648: True
//       -10534 = -10534: True
//       -189 = -189: True
//       0 = 0: True
//       17 = 17: True
//       113439 = 113439: True
//       2147483647 = 2147483647: True
Dim integers() As Integer = { Int32.MinValue, -10534, -189, 0, 17, 113439,
                              Int32.MaxValue }
Dim constructed, assigned As BigInteger

For Each number As Integer In integers
   constructed = New BigInteger(number)
   assigned = number
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned, 
                     constructed.Equals(assigned)) 
Next
' The example displays the following output:
'       -2147483648 = -2147483648: True
'       -10534 = -10534: True
'       -189 = -189: True
'       0 = 0: True
'       17 = 17: True
'       113439 = 113439: True
'       2147483647 = 2147483647: True

Commenti

Non esiste alcuna perdita di precisione quando si crea un'istanza di un BigInteger oggetto usando questo costruttore.

Il BigInteger valore risultante dalla chiamata a questo costruttore è identico al valore che determina l'assegnazione di un Int32 valore a un BigIntegeroggetto .

La BigInteger struttura non include costruttori con un parametro di tipo Byte, , Int16SByteo UInt16. Tuttavia, il Int32 tipo supporta la conversione implicita di interi con segno a 8 bit e a 16 bit e interi senza segno a interi con segno a 32 bit. Di conseguenza, questo costruttore viene chiamato se value è uno di questi quattro tipi integrali.

Si applica a

BigInteger(Int64)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

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

public:
 BigInteger(long value);
public BigInteger (long value);
new System.Numerics.BigInteger : int64 -> System.Numerics.BigInteger
Public Sub New (value As Long)

Parametri

value
Int64

Intero con segno a 64 bit.

Esempio

Nell'esempio seguente viene chiamato il costruttore per creare BigInteger un'istanza BigInteger(Int64) di valori da una matrice di interi a 64 bit. Usa anche la conversione implicita per assegnare ogni valore intero a 64 bit a una BigInteger variabile. Confronta quindi i due valori per stabilire che i valori risultanti BigInteger sono uguali.

long[] longs = { Int64.MinValue, -10534, -189, 0, 17, 113439,
                 Int64.MaxValue };
BigInteger constructed, assigned;

foreach (long number in longs)
{
   constructed = new BigInteger(number);
   assigned = number;
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned,
                     constructed.Equals(assigned));
}
// The example displays the following output:
//       -2147483648 = -2147483648: True
//       -10534 = -10534: True
//       -189 = -189: True
//       0 = 0: True
//       17 = 17: True
//       113439 = 113439: True
//       2147483647 = 2147483647: True
Dim longs() As Long = { Int64.MinValue, -10534, -189, 0, 17, 113439,
                              Int64.MaxValue }
Dim constructed, assigned As BigInteger

For Each number As Long In longs
   constructed = New BigInteger(number)
   assigned = number
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned, 
                     constructed.Equals(assigned)) 
Next
' The example displays the following output:
'       -2147483648 = -2147483648: True
'       -10534 = -10534: True
'       -189 = -189: True
'       0 = 0: True
'       17 = 17: True
'       113439 = 113439: True
'       2147483647 = 2147483647: True

Commenti

Non esiste alcuna perdita di precisione quando si crea un'istanza di un BigInteger oggetto usando questo costruttore.

Il BigInteger valore risultante dalla chiamata a questo costruttore è identico al valore che determina l'assegnazione di un Int64 valore a un BigIntegeroggetto .

Si applica a

BigInteger(Single)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

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

public:
 BigInteger(float value);
public BigInteger (float value);
new System.Numerics.BigInteger : single -> System.Numerics.BigInteger
Public Sub New (value As Single)

Parametri

value
Single

Valore a virgola mobile e precisione singola.

Eccezioni

Esempio

Nell'esempio seguente viene illustrato l'uso del costruttore per creare un'istanza BigInteger(Single) di un BigInteger oggetto. Illustra anche la perdita di precisione che può verificarsi quando si usa il Single tipo di dati. Viene Single assegnato un valore negativo di grandi dimensioni, che viene quindi assegnato a un BigInteger oggetto. Come illustrato nell'output, questa assegnazione comporta una perdita di precisione. Entrambi i valori vengono quindi incrementati di uno. L'output mostra che l'oggetto BigInteger riflette il valore modificato, mentre l'oggetto Single non lo fa.

// Create a BigInteger from a large negative Single value
float negativeSingle = Single.MinValue;
BigInteger negativeNumber = new BigInteger(negativeSingle);

Console.WriteLine(negativeSingle.ToString("N0"));
Console.WriteLine(negativeNumber.ToString("N0"));

negativeSingle++;
negativeNumber++;

Console.WriteLine(negativeSingle.ToString("N0"));
Console.WriteLine(negativeNumber.ToString("N0"));
// The example displays the following output:
//       -340,282,300,000,000,000,000,000,000,000,000,000,000
//       -340,282,346,638,528,859,811,704,183,484,516,925,440
//       -340,282,300,000,000,000,000,000,000,000,000,000,000
//       -340,282,346,638,528,859,811,704,183,484,516,925,439
' Create a BigInteger from a large negative Single value
Dim negativeSingle As Single = Single.MinValue
Dim negativeNumber As New BigInteger(negativeSingle)

Console.WriteLine(negativeSingle.ToString("N0"))
Console.WriteLine(negativeNumber.ToString("N0"))

negativeSingle += 1
negativeNumber += 1
Console.WriteLine(negativeSingle.ToString("N0"))
Console.WriteLine(negativeNumber.ToString("N0"))
' The example displays the following output:
'       -340,282,300,000,000,000,000,000,000,000,000,000,000
'       -340,282,346,638,528,859,811,704,183,484,516,925,440
'       -340,282,300,000,000,000,000,000,000,000,000,000,000
'       -340,282,346,638,528,859,811,704,183,484,516,925,439

Commenti

Qualsiasi parte frazionaria del value parametro viene troncata quando si crea un'istanza di un BigInteger oggetto .

A causa della mancanza di precisione del Single tipo di dati, la chiamata a questo costruttore può comportare una perdita di dati.

Il BigInteger valore risultante dalla chiamata a questo costruttore è identico al valore risultante dall'assegnazione esplicita di un Single valore a un oggetto BigInteger.

Si applica a

BigInteger(UInt32)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Importante

Questa API non è conforme a CLS.

Alternativa conforme a CLS
System.Numerics.BigInteger.BigInteger(Int64)

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

public:
 BigInteger(System::UInt32 value);
[System.CLSCompliant(false)]
public BigInteger (uint value);
[<System.CLSCompliant(false)>]
new System.Numerics.BigInteger : uint32 -> System.Numerics.BigInteger
Public Sub New (value As UInteger)

Parametri

value
UInt32

Valore intero senza segno a 32 bit.

Attributi

Esempio

Nell'esempio seguente viene utilizzato il BigInteger(UInt32) costruttore e un'istruzione di assegnazione per inizializzare i BigInteger valori da una matrice di interi senza segno a 32 bit. Confronta quindi i due valori per dimostrare che i due metodi di inizializzazione di un BigInteger valore producono risultati identici.

uint[] unsignedValues = { 0, 16704, 199365, UInt32.MaxValue };
foreach (uint unsignedValue in unsignedValues)
{
   BigInteger constructedNumber = new BigInteger(unsignedValue);
   BigInteger assignedNumber = unsignedValue;
   if (constructedNumber.Equals(assignedNumber))
      Console.WriteLine("Both methods create a BigInteger whose value is {0:N0}.",
                        constructedNumber);
   else
      Console.WriteLine("{0:N0} ≠ {1:N0}", constructedNumber, assignedNumber);
}
// The example displays the following output:
//    Both methods create a BigInteger whose value is 0.
//    Both methods create a BigInteger whose value is 16,704.
//    Both methods create a BigInteger whose value is 199,365.
//    Both methods create a BigInteger whose value is 4,294,967,295.
Dim unsignedValues() As UInteger = { 0, 16704, 199365, UInt32.MaxValue }
For Each unsignedValue As UInteger In unsignedValues
   Dim constructedNumber As New BigInteger(unsignedValue)
   Dim assignedNumber As BigInteger = unsignedValue
   If constructedNumber.Equals(assignedNumber) Then
      Console.WriteLine("Both methods create a BigInteger whose value is {0:N0}.",
                        constructedNumber)
   Else
      Console.WriteLine("{0:N0} ≠ {1:N0}", constructedNumber, assignedNumber)
   End If                         
Next
' The example displays the following output:
'    Both methods create a BigInteger whose value is 0.
'    Both methods create a BigInteger whose value is 16,704.
'    Both methods create a BigInteger whose value is 199,365.
'    Both methods create a BigInteger whose value is 4,294,967,295.

Commenti

Non si verifica alcuna perdita di precisione durante la creazione di un'istanza di utilizzando BigInteger questo costruttore.

Il BigInteger valore risultante dalla chiamata a questo costruttore è identico al valore risultante dall'assegnazione di un UInt32 valore a un oggetto BigInteger.

Si applica a

BigInteger(UInt64)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Importante

Questa API non è conforme a CLS.

Alternativa conforme a CLS
System.Numerics.BigInteger.BigInteger(Double)

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

public:
 BigInteger(System::UInt64 value);
[System.CLSCompliant(false)]
public BigInteger (ulong value);
[<System.CLSCompliant(false)>]
new System.Numerics.BigInteger : uint64 -> System.Numerics.BigInteger
Public Sub New (value As ULong)

Parametri

value
UInt64

Intero senza segno a 64 bit.

Attributi

Esempio

Nell'esempio seguente viene utilizzato il costruttore per creare un'istanza BigInteger(UInt64) di un BigInteger oggetto il cui valore è uguale a MaxValue.

ulong unsignedValue = UInt64.MaxValue;
BigInteger number = new BigInteger(unsignedValue);
Console.WriteLine(number.ToString("N0"));
// The example displays the following output:
//       18,446,744,073,709,551,615
Dim unsignedValue As ULong = UInt64.MaxValue
Dim number As New BigInteger(unsignedValue)
Console.WriteLine(number.ToString("N0"))       
' The example displays the following output:
'       18,446,744,073,709,551,615

Commenti

Non si verifica alcuna perdita di precisione durante la creazione di un'istanza di utilizzando BigInteger questo costruttore.

Il BigInteger valore risultante dalla chiamata a questo costruttore è identico al valore risultante dall'assegnazione di un UInt64 valore a un oggetto BigInteger.

Si applica a

BigInteger(ReadOnlySpan<Byte>, Boolean, Boolean)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

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.

public BigInteger (ReadOnlySpan<byte> value, bool isUnsigned = false, bool isBigEndian = false);
new System.Numerics.BigInteger : ReadOnlySpan<byte> * bool * bool -> System.Numerics.BigInteger
Public Sub New (value As ReadOnlySpan(Of Byte), Optional isUnsigned As Boolean = false, Optional isBigEndian As Boolean = false)

Parametri

value
ReadOnlySpan<Byte>

Intervallo di byte di sola lettura che rappresentano i dati big integer.

isUnsigned
Boolean

true per indicare che value usa la codifica senza segno; in caso contrario, false (valore predefinito).

isBigEndian
Boolean

true per indicare value che è in ordine di byte big-endian; in caso contrario, false (valore predefinito).

Si applica a