BigInteger.Explicit Opérateur

Définition

Définit une conversion explicite entre un objet BigInteger et un autre type.

Surcharges

Explicit(BigInteger to SByte)

Définit une conversion explicite d'un objet BigInteger en valeur 8 bits signée.

Cette API n'est pas conforme CLS. L’alternative conforme est Int16.

Explicit(Single to BigInteger)

Définit une conversion explicite d'une valeur Single en valeur BigInteger.

Explicit(Complex to BigInteger)

Convertit explicitement une Complex valeur en un grand entier.

Explicit(BigInteger to UIntPtr)

Convertit explicitement un entier volumineux en valeur UIntPtr .

Explicit(BigInteger to UInt64)

Définit une conversion explicite d’un objet BigInteger en valeur d’entier 64 bits non signé.

Cette API n'est pas conforme CLS. L’alternative conforme est Double.

Explicit(BigInteger to UInt32)

Définit une conversion explicite d’un objet BigInteger en valeur d’entier 32 bits non signé.

Cette API n'est pas conforme CLS. L’alternative conforme est Int64.

Explicit(BigInteger to UInt16)

Définit une conversion explicite d'un objet BigInteger en valeur entière 16 bits non signée.

Cette API n'est pas conforme CLS. L’alternative conforme est Int32.

Explicit(BigInteger to UInt128)

Convertit explicitement un entier volumineux en valeur UInt128 .

Explicit(BigInteger to Single)

Définit une conversion explicite d'un objet BigInteger en valeur à virgule flottante simple précision.

Explicit(BigInteger to IntPtr)

Convertit explicitement un entier volumineux en valeur IntPtr .

Explicit(BigInteger to Int64)

Définit une conversion explicite d’un objet BigInteger en valeur d’entier 64 bits signé.

Explicit(BigInteger to Int16)

Définit une conversion explicite d'un objet BigInteger en valeur d'entier 16 bits signé.

Explicit(BigInteger to Int128)

Convertit explicitement un entier volumineux en valeur Int128 .

Explicit(BigInteger to Half)

Convertit explicitement un entier volumineux en valeur Half .

Explicit(BigInteger to Double)

Définit une conversion explicite d'un objet BigInteger en valeur Double.

Explicit(BigInteger to Decimal)

Définit une conversion explicite d'un objet BigInteger en valeur Decimal.

Explicit(BigInteger to Char)

Convertit explicitement un entier volumineux en valeur Char .

Explicit(BigInteger to Byte)

Définit une conversion explicite d'un objet BigInteger en valeur d'octet non signée.

Explicit(Half to BigInteger)

Convertit explicitement une Half valeur en un grand entier.

Explicit(Double to BigInteger)

Définit une conversion explicite d'une valeur Double en valeur BigInteger.

Explicit(Decimal to BigInteger)

Définit une conversion explicite d'un objet Decimal en valeur BigInteger.

Explicit(BigInteger to Int32)

Définit une conversion explicite d’un objet BigInteger en valeur d’entier 32 bits signé.

Explicit(BigInteger to SByte)

Important

Cette API n’est pas conforme CLS.

Alternative à la conformité CLS
System.Int16

Définit une conversion explicite d'un objet BigInteger en valeur 8 bits signée.

Cette API n'est pas conforme CLS. L’alternative conforme est Int16.

public:
 static explicit operator System::SByte(System::Numerics::BigInteger value);
[System.CLSCompliant(false)]
public static explicit operator sbyte (System.Numerics.BigInteger value);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Numerics.BigInteger -> sbyte
Public Shared Narrowing Operator CType (value As BigInteger) As SByte

Paramètres

value
BigInteger

Valeur à convertir en valeur 8 bits signée.

Retours

Objet qui contient la valeur du paramètre value.

Attributs

Exceptions

value est inférieur à SByte.MinValue ou supérieur à SByte.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en SByte valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de SByte données.

// BigInteger to SByte conversion.
BigInteger goodSByte = BigInteger.MinusOne;
BigInteger badSByte = -130;

sbyte sByteFromBigInteger;

// Successful conversion using cast operator.
sByteFromBigInteger = (sbyte) goodSByte;
Console.WriteLine(sByteFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   sByteFromBigInteger = (sbyte) badSByte;
   Console.WriteLine(sByteFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badSByte, e.Message);
}
Console.WriteLine();
' BigInteger to SByte conversion.
Dim goodSByte As BigInteger = BigInteger.MinusOne
Dim badSByte As BigInteger = -130

Dim sByteFromBigInteger As SByte

' Convert using CType function.
sByteFromBigInteger = CType(goodSByte, SByte)
Console.WriteLine(sByteFromBigInteger)
' Convert using CSByte function.
sByteFromBigInteger = CSByte(goodSByte)
Console.WriteLine(sByteFromBigInteger)

' Handle conversion that should result in overflow.
Try
   sByteFromBigInteger = CType(badSByte, SByte)
   Console.WriteLine(sByteFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badSByte, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CSByte en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de SByte données. Il n’y a aucune perte de précision dans la valeur résultante SByte si la conversion réussit.

S’applique à

Explicit(Single to BigInteger)

Définit une conversion explicite d'une valeur Single en valeur BigInteger.

public:
 static explicit operator System::Numerics::BigInteger(float value);
public static explicit operator System.Numerics.BigInteger (float value);
static member op_Explicit : single -> System.Numerics.BigInteger
Public Shared Narrowing Operator CType (value As Single) As BigInteger

Paramètres

value
Single

Valeur à convertir en BigInteger.

Retours

Objet qui contient la valeur du paramètre value.

Exceptions

Exemples

L’exemple suivant convertit les éléments individuels d’un tableau de Single valeurs en BigInteger objets, puis affiche le résultat de chaque conversion. Notez que toute partie fractionnaire d’une Single valeur est tronquée pendant la conversion.

float[] singles = { Single.MinValue, -1.430955172e03f, 2.410970032e05f,
                    Single.MaxValue, Single.PositiveInfinity,
                     Single.NegativeInfinity, Single.NaN };
BigInteger number;

Console.WriteLine("{0,37} {1,37}\n", "Single", "BigInteger");

foreach (float value in singles)
{
   try {
      number = (BigInteger) value;
      Console.WriteLine("{0,37} {1,37}", value, number);
   }
   catch (OverflowException) {
      Console.WriteLine("{0,37} {1,37}", value, "OverflowException");
   }
}
// The example displays the following output:
//           Single                            BigInteger
//
//    -3.402823E+38   -3.4028234663852885981170418348E+38
//        -1430.955                                 -1430
//           241097                                241097
//     3.402823E+38    3.4028234663852885981170418348E+38
//         Infinity                     OverflowException
//        -Infinity                     OverflowException
//              NaN                     OverflowException
Dim singles() As Single = { Single.MinValue, -1.430955172e03, 2.410970032e05, 
                            Single.MaxValue, Single.PositiveInfinity, 
                            Single.NegativeInfinity, Single.NaN }
Dim number As BigInteger

Console.WriteLine("{0,37} {1,37}", "Single", "BigInteger")
Console.WriteLine()
For Each value As Single In singles
   Try
      number = CType(value, BigInteger)
      Console.WriteLine("{0,37} {1,37}", value, number)
   Catch e As OverflowException
      Console.WriteLine("{0,37} {1,37}", value, "OverflowException")
   End Try
Next     
' The example displays the following output:
'           Single                            BigInteger
' 
'    -3.402823E+38   -3.4028234663852885981170418348E+38
'        -1430.955                                 -1430
'           241097                                241097
'     3.402823E+38    3.4028234663852885981170418348E+38
'         Infinity                     OverflowException
'        -Infinity                     OverflowException
'              NaN                     OverflowException

Remarques

Toute partie fractionnaire du value paramètre est tronquée avant la conversion.

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Étant donné que la conversion de Single à BigInteger peut impliquer la troncation d’une partie fractionnaire de value, les compilateurs de langage n’effectuent pas cette conversion automatiquement. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType dans Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Pour les langues qui ne prennent pas en charge les opérateurs personnalisés, la méthode alternative est BigInteger.BigInteger(Single).

S’applique à

Explicit(Complex to BigInteger)

Convertit explicitement une Complex valeur en un grand entier.

public:
 static explicit operator System::Numerics::BigInteger(System::Numerics::Complex value);
public static explicit operator System.Numerics.BigInteger (System.Numerics.Complex value);
static member op_Explicit : System.Numerics.Complex -> System.Numerics.BigInteger
Public Shared Narrowing Operator CType (value As Complex) As BigInteger

Paramètres

value
Complex

La valeur à convertir.

Retours

value converti en un grand entier.

S’applique à

Explicit(BigInteger to UIntPtr)

Important

Cette API n’est pas conforme CLS.

Convertit explicitement un entier volumineux en valeur UIntPtr .

public:
 static explicit operator UIntPtr(System::Numerics::BigInteger value);
[System.CLSCompliant(false)]
public static explicit operator UIntPtr (System.Numerics.BigInteger value);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Numerics.BigInteger -> unativeint
Public Shared Narrowing Operator CType (value As BigInteger) As UIntPtr

Paramètres

value
BigInteger

La valeur à convertir.

Retours

UIntPtr

unativeint

value converti en UIntPtr valeur.

Attributs

S’applique à

Explicit(BigInteger to UInt64)

Important

Cette API n’est pas conforme CLS.

Alternative à la conformité CLS
System.Double

Définit une conversion explicite d’un objet BigInteger en valeur d’entier 64 bits non signé.

Cette API n'est pas conforme CLS. L’alternative conforme est Double.

public:
 static explicit operator System::UInt64(System::Numerics::BigInteger value);
[System.CLSCompliant(false)]
public static explicit operator ulong (System.Numerics.BigInteger value);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Numerics.BigInteger -> uint64
Public Shared Narrowing Operator CType (value As BigInteger) As ULong

Paramètres

value
BigInteger

Valeur à convertir en entier 64 bits non signé.

Retours

Objet qui contient la valeur du paramètre value.

Attributs

Exceptions

value est inférieur à UInt64.MinValue ou supérieur à UInt64.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en UInt64 valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de UInt64 données.

// BigInteger to UInt64 conversion.
BigInteger goodULong = 2000000000;
BigInteger badULong = BigInteger.Pow(goodULong, 3);

ulong uLongFromBigInteger;

// Successful conversion using cast operator.
uLongFromBigInteger = (ulong) goodULong;
Console.WriteLine(uLongFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   uLongFromBigInteger = (ulong) badULong;
   Console.WriteLine(uLongFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badULong, e.Message);
}
Console.WriteLine();
' BigInteger to UInt64 conversion.
Dim goodULong As BigInteger = 2000000000
Dim badULong As BigInteger = BigInteger.Pow(goodULong, 3)

Dim uLongFromBigInteger As ULong

' Convert using CType function.
uLongFromBigInteger = CType(goodULong, ULong)
Console.WriteLine(uLongFromBigInteger)
' Convert using CULng function.
uLongFromBigInteger = CULng(goodULong)
Console.WriteLine(uLongFromBigInteger)

' Handle conversion that should result in overflow.
Try
   uLongFromBigInteger = CType(badULong, ULong)
   Console.WriteLine(uLongFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badULong, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CULng en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de UInt64 données. Il n’y a aucune perte de précision dans la valeur résultante UInt64 si la conversion réussit.

S’applique à

Explicit(BigInteger to UInt32)

Important

Cette API n’est pas conforme CLS.

Alternative à la conformité CLS
System.Int64

Définit une conversion explicite d’un objet BigInteger en valeur d’entier 32 bits non signé.

Cette API n'est pas conforme CLS. L’alternative conforme est Int64.

public:
 static explicit operator System::UInt32(System::Numerics::BigInteger value);
[System.CLSCompliant(false)]
public static explicit operator uint (System.Numerics.BigInteger value);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Numerics.BigInteger -> uint32
Public Shared Narrowing Operator CType (value As BigInteger) As UInteger

Paramètres

value
BigInteger

Valeur à convertir en entier 32 bits non signé.

Retours

Objet qui contient la valeur du paramètre value.

Attributs

Exceptions

value est inférieur à UInt32.MinValue ou supérieur à UInt32.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en UInt32 valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de UInt32 données.

// BigInteger to UInt32 conversion.
BigInteger goodUInteger = 200000;
BigInteger badUInteger = 65000000000;

uint uIntegerFromBigInteger;

// Successful conversion using cast operator.
uIntegerFromBigInteger = (uint) goodInteger;
Console.WriteLine(uIntegerFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   uIntegerFromBigInteger = (uint) badUInteger;
   Console.WriteLine(uIntegerFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badUInteger, e.Message);
}
Console.WriteLine();
' BigInteger to UInt32 conversion.
Dim goodUInteger As BigInteger = 200000
Dim badUInteger As BigInteger = 65000000000

Dim uIntegerFromBigInteger As UInteger

' Convert using CType function.
uIntegerFromBigInteger = CType(goodInteger, UInteger)
Console.WriteLine(uIntegerFromBigInteger)
' Convert using CUInt function.
uIntegerFromBigInteger = CUInt(goodInteger)
Console.WriteLine(uIntegerFromBigInteger)

' Handle conversion that should result in overflow.
Try
   uIntegerFromBigInteger = CType(badUInteger, UInteger)
   Console.WriteLine(uIntegerFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badUInteger, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CUInt en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de UInt32 données. Il n’y a aucune perte de précision dans la valeur résultante UInt32 si la conversion réussit.

S’applique à

Explicit(BigInteger to UInt16)

Important

Cette API n’est pas conforme CLS.

Alternative à la conformité CLS
System.Int32

Définit une conversion explicite d'un objet BigInteger en valeur entière 16 bits non signée.

Cette API n'est pas conforme CLS. L’alternative conforme est Int32.

public:
 static explicit operator System::UInt16(System::Numerics::BigInteger value);
[System.CLSCompliant(false)]
public static explicit operator ushort (System.Numerics.BigInteger value);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Numerics.BigInteger -> uint16
Public Shared Narrowing Operator CType (value As BigInteger) As UShort

Paramètres

value
BigInteger

Valeur à convertir en entier 16 bits non signé.

Retours

Objet qui contient la valeur du paramètre value.

Attributs

Exceptions

value est inférieur à UInt16.MinValue ou supérieur à UInt16.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en UInt16 valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de UInt16 données.

// BigInteger to UInt16 conversion.
BigInteger goodUShort = 20000;
BigInteger badUShort = 66000;

ushort uShortFromBigInteger;

// Successful conversion using cast operator.
uShortFromBigInteger = (ushort) goodUShort;
Console.WriteLine(uShortFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   uShortFromBigInteger = (ushort) badUShort;
   Console.WriteLine(uShortFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badUShort, e.Message);
}
Console.WriteLine();
' BigInteger to UInt16 conversion.
Dim goodUShort As BigInteger = 20000
Dim badUShort As BigInteger = 66000

Dim uShortFromBigInteger As UShort

' Convert using CType function.
uShortFromBigInteger = CType(goodUShort, UShort)
Console.WriteLine(uShortFromBigInteger)
' Convert using CUShort function.
uShortFromBigInteger = CUShort(goodUShort)
Console.WriteLine(uShortFromBigInteger)

' Handle conversion that should result in overflow.
Try
   uShortFromBigInteger = CType(badUShort, UShort)
   Console.WriteLine(uShortFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badUShort, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CUShort en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de UInt16 données. Il n’y a aucune perte de précision dans la valeur résultante UInt16 si la conversion réussit.

S’applique à

Explicit(BigInteger to UInt128)

Important

Cette API n’est pas conforme CLS.

Convertit explicitement un entier volumineux en valeur UInt128 .

public:
 static explicit operator UInt128(System::Numerics::BigInteger value);
[System.CLSCompliant(false)]
public static explicit operator UInt128 (System.Numerics.BigInteger value);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Numerics.BigInteger -> UInt128
Public Shared Narrowing Operator CType (value As BigInteger) As UInt128

Paramètres

value
BigInteger

La valeur à convertir.

Retours

value converti en UInt128 valeur.

Attributs

S’applique à

Explicit(BigInteger to Single)

Définit une conversion explicite d'un objet BigInteger en valeur à virgule flottante simple précision.

public:
 static explicit operator float(System::Numerics::BigInteger value);
public static explicit operator float (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> single
Public Shared Narrowing Operator CType (value As BigInteger) As Single

Paramètres

value
BigInteger

Valeur à convertir en valeur à virgule flottante simple précision.

Retours

Objet qui contient la représentation la plus proche possible du paramètre value.

Exemples

L’exemple suivant illustre la conversion de BigInteger en Single valeurs.

// BigInteger to Single conversion.
BigInteger goodSingle = (BigInteger) 102.43e22F;
BigInteger badSingle = (BigInteger) float.MaxValue;
badSingle = badSingle * 2;

float singleFromBigInteger;

// Successful conversion using cast operator.
singleFromBigInteger = (float) goodSingle;
Console.WriteLine(singleFromBigInteger);

// Convert an out-of-bounds BigInteger value to a Single.
singleFromBigInteger = (float) badSingle;
Console.WriteLine(singleFromBigInteger);
' BigInteger to Single conversion.
Dim goodSingle As BigInteger = 102.43e22
Dim badSingle As BigInteger = CType(Single.MaxValue, BigInteger)  
badSingle = badSingle * 2

Dim singleFromBigInteger As Single

' Convert using CType function.
singleFromBigInteger = CType(goodSingle, Single)
Console.WriteLine(singleFromBigInteger)
' Convert using CSng function.
singleFromBigInteger = CSng(goodSingle)
Console.WriteLine(singleFromBigInteger)

' Convert an out-of-bounds BigInteger value to a Single.
singleFromBigInteger = CType(badSingle, Single)
Console.WriteLine(singleFromBigInteger)

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données ou une perte de précision. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CSng en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que la BigInteger valeur peut se trouver en dehors de la plage du Single type de données, cette opération est une conversion de rétrécissement. Si la conversion échoue, elle ne lève pas de OverflowException. Au lieu de cela, si la BigInteger valeur est inférieure Single.MinValueà , la valeur résultante Single est Single.NegativeInfinity. Si la BigInteger valeur est supérieure Single.MaxValueà , la valeur résultante Single est Single.PositiveInfinity.

La conversion d’un BigInteger en un Single peut entraîner une perte de précision. Dans certains cas, la perte de précision peut entraîner la réussite de l’opération de conversion ou de conversion, même si la BigInteger valeur se trouve en dehors de la plage du type de Single données. L'exemple suivant illustre cette situation. Il affecte la valeur maximale d’un Single à deux BigInteger variables, incrémente une BigInteger variable de 9,999e291 et teste l’égalité entre les deux variables. Comme prévu, l’appel à la BigInteger.Equals(BigInteger) méthode montre qu’elles sont inégales. Toutefois, la conversion de la plus grande BigInteger valeur en un Single réussit, bien que la BigInteger valeur dépasse Single.MaxValuedésormais .

// Increase a BigInteger so it exceeds Single.MaxValue.
BigInteger number1 = (BigInteger) Single.MaxValue;
BigInteger number2 = number1;
number2 = number2 + (BigInteger) 9.999e30;
// Compare the BigInteger values for equality.
Console.WriteLine("BigIntegers equal: {0}", number2.Equals(number1));

// Convert the BigInteger to a Single.
float sng = (float) number2;

// Display the two values.
Console.WriteLine("BigInteger: {0}", number2);
Console.WriteLine("Single:     {0}", sng);
// The example displays the following output:
//       BigIntegers equal: False
//       BigInteger: 3.4028235663752885981170396038E+38
//       Single:     3.402823E+38
' Increase a BigInteger so it exceeds Single.MaxValue.
Dim number1 As BigInteger = CType(Single.MaxValue, BigInteger)
Dim number2 As BigInteger = number1
number2 = number2 + 9.999e30
' Compare the BigInteger values for equality.
Console.WriteLine("BigIntegers equal: {0}", number2.Equals(number1))

' Convert the BigInteger to a Single.
Dim sng As Single = CType(number2, Single)

' Display the two values.
Console.WriteLine("BigInteger: {0}", number2)
Console.WriteLine("Single:     {0}", sng)      
' The example displays the following output:
'       BigIntegers equal: False
'       BigInteger: 3.4028235663752885981170396038E+38
'       Single:     3.402823E+38

S’applique à

Explicit(BigInteger to IntPtr)

Convertit explicitement un entier volumineux en valeur IntPtr .

public:
 static explicit operator IntPtr(System::Numerics::BigInteger value);
public static explicit operator IntPtr (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> nativeint
Public Shared Narrowing Operator CType (value As BigInteger) As IntPtr

Paramètres

value
BigInteger

La valeur à convertir.

Retours

IntPtr

nativeint

value converti en IntPtr valeur.

S’applique à

Explicit(BigInteger to Int64)

Définit une conversion explicite d’un objet BigInteger en valeur d’entier 64 bits signé.

public:
 static explicit operator long(System::Numerics::BigInteger value);
public static explicit operator long (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> int64
Public Shared Narrowing Operator CType (value As BigInteger) As Long

Paramètres

value
BigInteger

Valeur à convertir en entier 64 bits signé.

Retours

Objet qui contient la valeur du paramètre value.

Exceptions

value est inférieur à Int64.MinValue ou supérieur à Int64.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en Int64 valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de Int64 données.

// BigInteger to Int64 conversion.
BigInteger goodLong = 2000000000;
BigInteger badLong = BigInteger.Pow(goodLong, 3);

long longFromBigInteger;

// Successful conversion using cast operator.
longFromBigInteger = (long) goodLong;
Console.WriteLine(longFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   longFromBigInteger = (long) badLong;
   Console.WriteLine(longFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badLong, e.Message);
}
Console.WriteLine();
' BigInteger to Int64 conversion.
Dim goodLong As BigInteger = 2000000000
Dim badLong As BigInteger = BigInteger.Pow(goodLong, 3)

Dim longFromBigInteger As Long

' Convert using CType function.
longFromBigInteger = CType(goodLong, Long)
Console.WriteLine(longFromBigInteger)
' Convert using CLng function.
longFromBigInteger = CLng(goodLong)
Console.WriteLine(longFromBigInteger)

' Handle conversion that should result in overflow.
Try
   longFromBigInteger = CType(badLong, Long)
   Console.WriteLine(longFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badLong, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CLng en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de Int64 données.

S’applique à

Explicit(BigInteger to Int16)

Définit une conversion explicite d'un objet BigInteger en valeur d'entier 16 bits signé.

public:
 static explicit operator short(System::Numerics::BigInteger value);
public static explicit operator short (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> int16
Public Shared Narrowing Operator CType (value As BigInteger) As Short

Paramètres

value
BigInteger

Valeur à convertir en entier 16 bits signé.

Retours

Objet qui contient la valeur du paramètre value.

Exceptions

value est inférieur à Int16.MinValue ou supérieur à Int16.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en Int16 valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de Int16 données.

// BigInteger to Int16 conversion.
BigInteger goodShort = 20000;
BigInteger badShort = 33000;

short shortFromBigInteger;

// Successful conversion using cast operator.
shortFromBigInteger = (short) goodShort;
Console.WriteLine(shortFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   shortFromBigInteger = (short) badShort;
   Console.WriteLine(shortFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badShort, e.Message);
}
Console.WriteLine();
' BigInteger to Int16 conversion.
Dim goodShort As BigInteger = 20000
Dim badShort As BigInteger = 33000

Dim shortFromBigInteger As Short

' Convert using CType function.
shortFromBigInteger = CType(goodShort, Short)
Console.WriteLine(shortFromBigInteger)
' Convert using CShort function.
shortFromBigInteger = CShort(goodShort)
Console.WriteLine(shortFromBigInteger)

' Handle conversion that should result in overflow.
Try
   shortFromBigInteger = CType(badShort, Short)
   Console.WriteLine(shortFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badShort, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CShort en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de Int16 données. Il n’y a aucune perte de précision dans la valeur résultante Int16 si la conversion réussit.

S’applique à

Explicit(BigInteger to Int128)

Convertit explicitement un entier volumineux en valeur Int128 .

public:
 static explicit operator Int128(System::Numerics::BigInteger value);
public static explicit operator Int128 (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> Int128
Public Shared Narrowing Operator CType (value As BigInteger) As Int128

Paramètres

value
BigInteger

La valeur à convertir.

Retours

value converti en Int128 valeur.

S’applique à

Explicit(BigInteger to Half)

Convertit explicitement un entier volumineux en valeur Half .

public:
 static explicit operator Half(System::Numerics::BigInteger value);
public static explicit operator Half (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> Half
Public Shared Narrowing Operator CType (value As BigInteger) As Half

Paramètres

value
BigInteger

La valeur à convertir.

Retours

value converti en Half valeur.

S’applique à

Explicit(BigInteger to Double)

Définit une conversion explicite d'un objet BigInteger en valeur Double.

public:
 static explicit operator double(System::Numerics::BigInteger value);
public static explicit operator double (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> double
Public Shared Narrowing Operator CType (value As BigInteger) As Double

Paramètres

value
BigInteger

Valeur à convertir en Double.

Retours

Objet qui contient la valeur du paramètre value.

Exemples

L’exemple suivant illustre la conversion de BigInteger en Double valeurs.

// BigInteger to Double conversion.
BigInteger goodDouble = (BigInteger) 102.43e22;
BigInteger badDouble = (BigInteger) Double.MaxValue;
badDouble = badDouble * 2;

double doubleFromBigInteger;

// successful conversion using cast operator.
doubleFromBigInteger = (double) goodDouble;
Console.WriteLine(doubleFromBigInteger);

// Convert an out-of-bounds BigInteger value to a Double.
doubleFromBigInteger = (double) badDouble;
Console.WriteLine(doubleFromBigInteger);
' BigInteger to Double conversion.
Dim goodDouble As BigInteger = 102.43e22
Dim badDouble As BigInteger = CType(Double.MaxValue, BigInteger)  
badDouble = badDouble * 2

Dim doubleFromBigInteger As Double

' Convert using CType function.
doubleFromBigInteger = CType(goodDouble, Double)
Console.WriteLine(doubleFromBigInteger)
' Convert using CDbl function.
doubleFromBigInteger = CDbl(goodDouble)
Console.WriteLine(doubleFromBigInteger)

' Convert an out-of-bounds BigInteger value to a Double.
doubleFromBigInteger = CType(badDouble, Double)
Console.WriteLine(doubleFromBigInteger)

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CDbl en Visual Basic) est utilisé.

Étant donné que la BigInteger valeur peut se trouver en dehors de la plage du Double type de données, cette opération est une conversion de rétrécissement. Si la conversion échoue, elle ne lève pas de OverflowException. Au lieu de cela, si la BigInteger valeur est inférieure Double.MinValueà , la valeur résultante Double est Double.NegativeInfinity. Si la BigInteger valeur est supérieure Double.MaxValueà , la valeur résultante Double est Double.PositiveInfinity.

La conversion d’un BigInteger en un Double peut entraîner une perte de précision. Dans certains cas, la perte de précision peut entraîner la réussite de l’opération de conversion ou de conversion, même si la BigInteger valeur se trouve en dehors de la plage du type de Double données. L'exemple suivant illustre cette situation. Il affecte la valeur maximale d’un Double à deux BigInteger variables, incrémente une BigInteger variable de 9,999e291 et teste l’égalité entre les deux variables. Comme prévu, l’appel à la BigInteger.Equals(BigInteger) méthode montre qu’elles sont inégales. Toutefois, la conversion de la plus grande BigInteger valeur en un Double réussit, bien que la BigInteger valeur dépasse Double.MaxValuedésormais .

// Increase a BigInteger so it exceeds Double.MaxValue.
BigInteger number1 = (BigInteger) Double.MaxValue;
BigInteger number2 = number1;
number2 = number2 + (BigInteger) 9.999e291;
// Compare the BigInteger values for equality.
Console.WriteLine("BigIntegers equal: {0}", number2.Equals(number1));

// Convert the BigInteger to a Double.
double dbl = (double) number2;

// Display the two values.
Console.WriteLine("BigInteger: {0}", number2);
Console.WriteLine("Double:     {0}", dbl);
// The example displays the following output:
//       BigIntegers equal: False
//       BigInteger: 1.7976931348623158081352742373E+308
//       Double:     1.79769313486232E+308
' Increase a BigInteger so it exceeds Double.MaxValue.
Dim number1 As BigInteger = CType(Double.MaxValue, BigInteger)
Dim number2 As BigInteger = number1
number2 = number2 + 9.999e291
' Compare the BigInteger values for equality.
Console.WriteLine("BigIntegers equal: {0}", number2.Equals(number1))

' Convert the BigInteger to a Double.
Dim dbl As Double = CType(number2, Double)

' Display the two values.
Console.WriteLine("BigInteger: {0}", number2)
Console.WriteLine("Double:     {0}", dbl)      
' The example displays the following output:
'       BigIntegers equal: False
'       BigInteger: 1.7976931348623158081352742373E+308
'       Double:     1.79769313486232E+308

S’applique à

Explicit(BigInteger to Decimal)

Définit une conversion explicite d'un objet BigInteger en valeur Decimal.

public:
 static explicit operator System::Decimal(System::Numerics::BigInteger value);
public static explicit operator decimal (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> decimal
Public Shared Narrowing Operator CType (value As BigInteger) As Decimal

Paramètres

value
BigInteger

Valeur à convertir en Decimal.

Retours

Objet qui contient la valeur du paramètre value.

Exceptions

value est inférieur à Decimal.MinValue ou supérieur à Decimal.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en Decimal valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de Decimal données.

// BigInteger to Decimal conversion.
BigInteger goodDecimal = 761652543;
BigInteger badDecimal = (BigInteger) Decimal.MaxValue;
badDecimal += BigInteger.One;

Decimal decimalFromBigInteger;

// Successful conversion using cast operator.
decimalFromBigInteger = (decimal) goodDecimal;
Console.WriteLine(decimalFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   decimalFromBigInteger = (decimal) badDecimal;
   Console.WriteLine(decimalFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badDecimal, e.Message);
}
Console.WriteLine();
' BigInteger to Decimal conversion.
Dim goodDecimal As BigInteger = 761652543
Dim badDecimal As BigInteger = CType(Decimal.MaxValue, BigInteger) 
badDecimal += BigInteger.One

Dim decimalFromBigInteger As Decimal

' Convert using CType function.
decimalFromBigInteger = CType(goodDecimal, Decimal)
Console.WriteLine(decimalFromBigInteger)
' Convert using CDec function.
decimalFromBigInteger = CDec(goodDecimal)
Console.WriteLine(decimalFromBigInteger)

' Handle conversion that should result in overflow.
Try
   decimalFromBigInteger = CType(badDecimal, Decimal)
   Console.WriteLine(decimalFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badDecimal, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CDec en Visual Basic) est utilisé.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de Decimal données.

S’applique à

Explicit(BigInteger to Char)

Convertit explicitement un entier volumineux en valeur Char .

public:
 static explicit operator char(System::Numerics::BigInteger value);
public static explicit operator char (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> char
Public Shared Narrowing Operator CType (value As BigInteger) As Char

Paramètres

value
BigInteger

La valeur à convertir.

Retours

value converti en Char valeur.

S’applique à

Explicit(BigInteger to Byte)

Définit une conversion explicite d'un objet BigInteger en valeur d'octet non signée.

public:
 static explicit operator System::Byte(System::Numerics::BigInteger value);
public static explicit operator byte (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> byte
Public Shared Narrowing Operator CType (value As BigInteger) As Byte

Paramètres

value
BigInteger

Valeur à convertir en Byte.

Retours

Objet qui contient la valeur du paramètre value.

Exceptions

value est inférieur à Byte.MinValue ou supérieur à Byte.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en Byte valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de Byte données.

// BigInteger to Byte conversion.
BigInteger goodByte = BigInteger.One;
BigInteger badByte = 256;

byte byteFromBigInteger;

// Successful conversion using cast operator.
byteFromBigInteger = (byte) goodByte;
Console.WriteLine(byteFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   byteFromBigInteger = (byte) badByte;
   Console.WriteLine(byteFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badByte, e.Message);
}
Console.WriteLine();
' BigInteger to Byte conversion.
Dim goodByte As BigInteger = BigInteger.One
Dim badByte As BigInteger = 256

Dim byteFromBigInteger As Byte   

' Convert using CType function.
byteFromBigInteger = CType(goodByte, Byte)
Console.WriteLine(byteFromBigInteger)
' Convert using CByte function.
byteFromBigInteger = CByte(goodByte)
Console.WriteLine(byteFromBigInteger)

' Handle conversion that should result in overflow.
Try
   byteFromBigInteger = CType(badByte, Byte)
   Console.WriteLine(byteFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badByte, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CByte en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de Byte données. Il n’y a aucune perte de précision dans la valeur résultante Byte si la conversion réussit.

S’applique à

Explicit(Half to BigInteger)

Convertit explicitement une Half valeur en un grand entier.

public:
 static explicit operator System::Numerics::BigInteger(Half value);
public static explicit operator System.Numerics.BigInteger (Half value);
static member op_Explicit : Half -> System.Numerics.BigInteger
Public Shared Narrowing Operator CType (value As Half) As BigInteger

Paramètres

value
Half

La valeur à convertir.

Retours

value converti en un grand entier.

S’applique à

Explicit(Double to BigInteger)

Définit une conversion explicite d'une valeur Double en valeur BigInteger.

public:
 static explicit operator System::Numerics::BigInteger(double value);
public static explicit operator System.Numerics.BigInteger (double value);
static member op_Explicit : double -> System.Numerics.BigInteger
Public Shared Narrowing Operator CType (value As Double) As BigInteger

Paramètres

value
Double

Valeur à convertir en BigInteger.

Retours

Objet qui contient la valeur du paramètre value.

Exceptions

Exemples

L’exemple suivant convertit les éléments individuels d’un tableau de Double valeurs en BigInteger objets, puis affiche le résultat de chaque conversion. Notez que toute partie fractionnaire d’une Double valeur est tronquée pendant la conversion.

double[] doubles = { Double.MinValue, -1.430955172e03, 2.410970032e05,
                     Double.MaxValue, Double.PositiveInfinity,
                     Double.NegativeInfinity, Double.NaN };
BigInteger number;

Console.WriteLine("{0,37} {1,37}\n", "Double", "BigInteger");

foreach (double value in doubles)
{
   try {
      number = (BigInteger) value;
      Console.WriteLine("{0,37} {1,37}", value, number);
   }
   catch (OverflowException) {
      Console.WriteLine("{0,37} {1,37}", value, "OverflowException");
   }
}
// The example displays the following output:
//                                Double                            BigInteger
//
//                -1.79769313486232E+308  -1.7976931348623157081452742373E+308
//                          -1430.955172                                 -1430
//                           241097.0032                                241097
//                 1.79769313486232E+308   1.7976931348623157081452742373E+308
//                              Infinity                     OverflowException
//                             -Infinity                     OverflowException
//                                   NaN                     OverflowException
Dim doubles() As Double = { Double.MinValue, -1.430955172e03, 2.410970032e05, 
                            Double.MaxValue, Double.PositiveInfinity, 
                            Double.NegativeInfinity, Double.NaN }
Dim number As BigInteger

Console.WriteLine("{0,37} {1,37}", "Double", "BigInteger")
Console.WriteLine()
For Each value As Double In doubles
   Try
      number = CType(value, BigInteger)
      Console.WriteLine("{0,37} {1,37}", value, number)
   Catch e As OverflowException
      Console.WriteLine("{0,37} {1,37}", value, "OverflowException")
   End Try      
Next
' The example displays the following output:
'                                Double                            BigInteger
' 
'                -1.79769313486232E+308  -1.7976931348623157081452742373E+308
'                          -1430.955172                                 -1430
'                           241097.0032                                241097
'                 1.79769313486232E+308   1.7976931348623157081452742373E+308
'                              Infinity                     OverflowException
'                             -Infinity                     OverflowException
'                                   NaN                     OverflowException

Remarques

Toute partie fractionnaire du value paramètre est tronquée avant la conversion.

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Étant donné que la conversion de Double à BigInteger peut impliquer la troncation d’une partie fractionnaire de value, les compilateurs de langage n’effectuent pas cette conversion automatiquement. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType dans Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Pour les langues qui ne prennent pas en charge les opérateurs personnalisés, la méthode alternative est BigInteger.BigInteger(Double).

S’applique à

Explicit(Decimal to BigInteger)

Définit une conversion explicite d'un objet Decimal en valeur BigInteger.

public:
 static explicit operator System::Numerics::BigInteger(System::Decimal value);
public static explicit operator System.Numerics.BigInteger (decimal value);
static member op_Explicit : decimal -> System.Numerics.BigInteger
Public Shared Narrowing Operator CType (value As Decimal) As BigInteger

Paramètres

value
Decimal

Valeur à convertir en BigInteger.

Retours

Objet qui contient la valeur du paramètre value.

Exemples

L’exemple suivant convertit les éléments individuels d’un tableau de Decimal valeurs en BigInteger objets, puis affiche le résultat de chaque conversion. Notez que toute partie fractionnaire d’une Decimal valeur est tronquée pendant la conversion.

decimal[] decimals = { Decimal.MinValue, -15632.991m, 9029321.12m,
                       Decimal.MaxValue };
BigInteger number;

Console.WriteLine("{0,35} {1,35}\n", "Decimal", "BigInteger");

foreach (decimal value in decimals)
{
   number = (BigInteger) value;
   Console.WriteLine("{0,35} {1,35}", value, number);
}
// The example displays the following output:
//
//                          Decimal                          BigInteger
//
//    -79228162514264337593543950335      -79228162514264337593543950335
//                       -15632.991                              -15632
//                       9029321.12                             9029321
//    79228162514264337593543950335       79228162514264337593543950335
' Explicit Decimal to BigInteger conversion
Dim decimals() As Decimal = { Decimal.MinValue, -15632.991d, 9029321.12d, 
                              Decimal.MaxValue }
Dim number As BigInteger 

Console.WriteLine("{0,35} {1,35}", "Decimal", "BigInteger")
Console.WriteLine()
For Each value As Decimal In decimals
   number = CType(value, BigInteger)
   Console.WriteLine("{0,35} {1,35}",
                     value, number)
Next
' The example displays the following output:
'
'                          Decimal                          BigInteger
'    
'    -79228162514264337593543950335      -79228162514264337593543950335
'                       -15632.991                              -15632
'                       9029321.12                             9029321
'    79228162514264337593543950335       79228162514264337593543950335

Remarques

Toute partie fractionnaire du value paramètre est tronquée avant la conversion.

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Étant donné que la conversion de Decimal à BigInteger peut impliquer la troncation d’une partie fractionnaire de value, les compilateurs de langage n’effectuent pas cette conversion automatiquement. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType dans Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Pour les langues qui ne prennent pas en charge les opérateurs personnalisés, la méthode alternative est BigInteger.BigInteger(Decimal).

S’applique à

Explicit(BigInteger to Int32)

Définit une conversion explicite d’un objet BigInteger en valeur d’entier 32 bits signé.

public:
 static explicit operator int(System::Numerics::BigInteger value);
public static explicit operator int (System.Numerics.BigInteger value);
static member op_Explicit : System.Numerics.BigInteger -> int
Public Shared Narrowing Operator CType (value As BigInteger) As Integer

Paramètres

value
BigInteger

Valeur à convertir en entier 32 bits signé.

Retours

Objet qui contient la valeur du paramètre value.

Exceptions

value est inférieur à Int32.MinValue ou supérieur à Int32.MaxValue.

Exemples

L’exemple suivant illustre la conversion de BigInteger en Int32 valeurs. Il gère également un OverflowException qui est levée, car la BigInteger valeur est en dehors de la plage du type de Int32 données.

// BigInteger to Int32 conversion.
BigInteger goodInteger = 200000;
BigInteger badInteger = 65000000000;

int integerFromBigInteger;

// Successful conversion using cast operator.
integerFromBigInteger = (int) goodInteger;
Console.WriteLine(integerFromBigInteger);

// Handle conversion that should result in overflow.
try
{
   integerFromBigInteger = (int) badInteger;
   Console.WriteLine(integerFromBigInteger);
}
catch (OverflowException e)
{
   Console.WriteLine("Unable to convert {0}:\n   {1}",
                     badInteger, e.Message);
}
Console.WriteLine();
' BigInteger to Int32 conversion.
Dim goodInteger As BigInteger = 200000
Dim badInteger As BigInteger = 65000000000

Dim integerFromBigInteger As Integer

' Convert using CType function.
integerFromBigInteger = CType(goodInteger, Integer)
Console.WriteLine(integerFromBigInteger)
' Convert using CInt function.
integerFromBigInteger = CInt(goodInteger)
Console.WriteLIne(integerFromBigInteger)

' Handle conversion that should result in overflow.
Try
   integerFromBigInteger = CType(badInteger, Integer)
   Console.WriteLine(integerFromBigInteger)
Catch e As OverflowException
   Console.WriteLine("Unable to convert {0}:{1}   {2}", _
                     badInteger, vbCrLf, e.Message)
End Try
Console.WriteLine()

Remarques

Les surcharges de la Explicit(Decimal to BigInteger) méthode définissent les types vers lesquels ou à partir desquels un BigInteger objet peut être converti. Les compilateurs de langage n’effectuent pas cette conversion automatiquement, car cela peut entraîner une perte de données. Au lieu de cela, ils effectuent la conversion uniquement si un opérateur de casting (en C#) ou une fonction de conversion (comme CType ou CInt en Visual Basic) est utilisé. Sinon, ils affichent une erreur du compilateur.

Étant donné que cette opération définit une conversion restrictive, elle peut lever un au moment de OverflowException l’exécution si la BigInteger valeur se trouve en dehors de la plage du type de Int32 données. Il n’y a aucune perte de précision dans la valeur résultante Int32 si la conversion réussit.

S’applique à