BigInteger.Explicit Operador

Definição

Define uma conversão explícita entre um objeto BigInteger e outro tipo.

Sobrecargas

Explicit(BigInteger to SByte)

Define uma conversão explícita de um objeto BigInteger em um valor de 8 bits com sinal.

Esta API não compatível com CLS. A alternativa em conformidade é Int16.

Explicit(Single to BigInteger)

Define uma conversão explícita de um valor Single para um valor BigInteger.

Explicit(Complex to BigInteger)

Converte explicitamente um Complex valor em um inteiro grande.

Explicit(BigInteger to UIntPtr)

Converte explicitamente um inteiro grande em um UIntPtr valor.

Explicit(BigInteger to UInt64)

Define uma conversão explícita de um objeto BigInteger em um valor inteiro sem sinal de 64 bits.

Esta API não compatível com CLS. A alternativa em conformidade é Double.

Explicit(BigInteger to UInt32)

Define uma conversão explícita de um objeto BigInteger em um valor inteiro sem sinal de 32 bits.

Esta API não compatível com CLS. A alternativa em conformidade é Int64.

Explicit(BigInteger to UInt16)

Define uma conversão explícita de um objeto BigInteger em um valor inteiro sem sinal de 16 bits.

Esta API não compatível com CLS. A alternativa em conformidade é Int32.

Explicit(BigInteger to UInt128)

Converte explicitamente um inteiro grande em um UInt128 valor.

Explicit(BigInteger to Single)

Define uma conversão explícita de um objeto BigInteger em um valor de ponto flutuante de precisão simples.

Explicit(BigInteger to IntPtr)

Converte explicitamente um inteiro grande em um IntPtr valor.

Explicit(BigInteger to Int64)

Define uma conversão explícita de um objeto BigInteger para um valor inteiro com sinal de 64 bits.

Explicit(BigInteger to Int16)

Define uma conversão explícita de um objeto BigInteger em um valor inteiro com sinal de 16 bits.

Explicit(BigInteger to Int128)

Converte explicitamente um inteiro grande em um Int128 valor.

Explicit(BigInteger to Half)

Converte explicitamente um inteiro grande em um Half valor.

Explicit(BigInteger to Double)

Define uma conversão explícita de um objeto BigInteger em um valor Double.

Explicit(BigInteger to Decimal)

Define uma conversão explícita de um objeto BigInteger em um valor Decimal.

Explicit(BigInteger to Char)

Converte explicitamente um inteiro grande em um Char valor.

Explicit(BigInteger to Byte)

Define uma conversão explícita de um objeto BigInteger em um valor de byte sem sinal.

Explicit(Half to BigInteger)

Converte explicitamente um Half valor em um inteiro grande.

Explicit(Double to BigInteger)

Define uma conversão explícita de um valor Double para um valor BigInteger.

Explicit(Decimal to BigInteger)

Define uma conversão explícita de um objeto Decimal em um valor BigInteger.

Explicit(BigInteger to Int32)

Define uma conversão explícita de um objeto BigInteger para um valor inteiro com sinal de 32 bits.

Explicit(BigInteger to SByte)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Importante

Esta API não está em conformidade com CLS.

Alternativa em conformidade com CLS
System.Int16

Define uma conversão explícita de um objeto BigInteger em um valor de 8 bits com sinal.

Esta API não compatível com CLS. A alternativa em conformidade é 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

Parâmetros

value
BigInteger

O valor a ser convertido em um valor de 8 bits com sinal.

Retornos

Um objeto que contém o valor do parâmetro value.

Atributos

Exceções

value é menor que SByte.MinValue ou é maior que SByte.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em SByte valores. Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do tipo de SByte dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou do qual um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CSByte no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como essa operação define uma conversão de estreitamento, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de SByte dados. Não haverá perda de precisão no valor resultante SByte se a conversão for bem-sucedida.

Aplica-se a

Explicit(Single to BigInteger)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um valor Single para um valor 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

Parâmetros

value
Single

O valor a ser convertido para um BigInteger.

Retornos

Um objeto que contém o valor do parâmetro value.

Exceções

Exemplos

O exemplo a seguir converte os elementos individuais em uma matriz de Single valores em BigInteger objetos e exibe o resultado de cada conversão. Observe que qualquer parte fracionária de um Single valor é truncada durante a conversão.

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

Comentários

Qualquer parte fracionária do value parâmetro é truncada antes da conversão.

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou do qual um BigInteger objeto pode ser convertido. Como a conversão de Single para BigInteger pode envolver truncamento de qualquer parte fracionária do value, os compiladores de linguagem não executam essa conversão automaticamente. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Para idiomas que não dão suporte a operadores personalizados, o método alternativo é BigInteger.BigInteger(Single).

Aplica-se a

Explicit(Complex to BigInteger)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Converte explicitamente um Complex valor em um inteiro grande.

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

Parâmetros

value
Complex

O valor a ser convertido.

Retornos

value convertido em um inteiro grande.

Aplica-se a

Explicit(BigInteger to UIntPtr)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Importante

Esta API não está em conformidade com CLS.

Converte explicitamente um inteiro grande em um UIntPtr valor.

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

Parâmetros

value
BigInteger

O valor a ser convertido.

Retornos

UIntPtr

unativeint

value convertido em UIntPtr valor.

Atributos

Aplica-se a

Explicit(BigInteger to UInt64)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Importante

Esta API não está em conformidade com CLS.

Alternativa em conformidade com CLS
System.Double

Define uma conversão explícita de um objeto BigInteger em um valor inteiro sem sinal de 64 bits.

Esta API não compatível com CLS. A alternativa em conformidade é 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

Parâmetros

value
BigInteger

O valor a ser convertido em um inteiro sem sinal de 64 bits.

Retornos

Um objeto que contém o valor do parâmetro value.

Atributos

Exceções

value é menor que UInt64.MinValue ou é maior que UInt64.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em UInt64 valores . Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do UInt64 tipo de dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CULng no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como essa operação define uma conversão de restrição, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de UInt64 dados. Não haverá perda de precisão no valor resultante UInt64 se a conversão for bem-sucedida.

Aplica-se a

Explicit(BigInteger to UInt32)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Importante

Esta API não está em conformidade com CLS.

Alternativa em conformidade com CLS
System.Int64

Define uma conversão explícita de um objeto BigInteger em um valor inteiro sem sinal de 32 bits.

Esta API não compatível com CLS. A alternativa em conformidade é 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

Parâmetros

value
BigInteger

O valor a ser convertido em um inteiro sem sinal de 32 bits.

Retornos

Um objeto que contém o valor do parâmetro value.

Atributos

Exceções

value é menor que UInt32.MinValue ou é maior que UInt32.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em UInt32 valores . Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do UInt32 tipo de dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CUInt no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como essa operação define uma conversão de restrição, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de UInt32 dados. Não haverá perda de precisão no valor resultante UInt32 se a conversão for bem-sucedida.

Aplica-se a

Explicit(BigInteger to UInt16)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Importante

Esta API não está em conformidade com CLS.

Alternativa em conformidade com CLS
System.Int32

Define uma conversão explícita de um objeto BigInteger em um valor inteiro sem sinal de 16 bits.

Esta API não compatível com CLS. A alternativa em conformidade é 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

Parâmetros

value
BigInteger

O valor a ser convertido em um inteiro sem sinal de 16 bits.

Retornos

Um objeto que contém o valor do parâmetro value.

Atributos

Exceções

value é menor que UInt16.MinValue ou é maior que UInt16.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em UInt16 valores . Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do UInt16 tipo de dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CUShort no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como essa operação define uma conversão de restrição, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de UInt16 dados. Não haverá perda de precisão no valor resultante UInt16 se a conversão for bem-sucedida.

Aplica-se a

Explicit(BigInteger to UInt128)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Importante

Esta API não está em conformidade com CLS.

Converte explicitamente um inteiro grande em um UInt128 valor.

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

Parâmetros

value
BigInteger

O valor a ser convertido.

Retornos

value convertido em UInt128 valor.

Atributos

Aplica-se a

Explicit(BigInteger to Single)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um objeto BigInteger em um valor de ponto flutuante de precisão simples.

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

Parâmetros

value
BigInteger

O valor a ser convertido em um ponto flutuante de precisão simples.

Retornos

Um objeto que contém a representação mais próxima possível do parâmetro value.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em Single valores .

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados ou perda de precisão. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CSng no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como o BigInteger valor pode estar fora do intervalo do tipo de Single dados, essa operação é uma conversão de restrição. Se a conversão não for bem-sucedida, ela não gerará um OverflowException. Em vez disso, se o BigInteger valor for menor que Single.MinValue, o valor resultante Single será Single.NegativeInfinity. Se o BigInteger valor for maior que Single.MaxValue, o valor resultante Single será Single.PositiveInfinity.

A conversão de um BigInteger em um Single pode envolver uma perda de precisão. Em alguns casos, a perda de precisão pode fazer com que a operação de conversão ou conversão seja bem-sucedida mesmo que o BigInteger valor esteja fora do intervalo do tipo de Single dados. O exemplo a seguir ilustra esse cenário. Ele atribui o valor máximo de a Single duas BigInteger variáveis, incrementa uma BigInteger variável em 9,999e291 e testa as duas variáveis quanto à igualdade. Conforme esperado, a chamada para o BigInteger.Equals(BigInteger) método mostra que eles são desiguais. No entanto, a conversão do valor maior BigInteger de volta para um Single é bem-sucedida, embora o BigInteger valor agora exceda Single.MaxValue.

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

Aplica-se a

Explicit(BigInteger to IntPtr)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Converte explicitamente um inteiro grande em um IntPtr valor.

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

Parâmetros

value
BigInteger

O valor a ser convertido.

Retornos

IntPtr

nativeint

value convertido em IntPtr valor.

Aplica-se a

Explicit(BigInteger to Int64)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um objeto BigInteger para um valor inteiro com sinal de 64 bits.

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

Parâmetros

value
BigInteger

O valor a ser convertido em um inteiro com sinal de 64 bits.

Retornos

Um objeto que contém o valor do parâmetro value.

Exceções

value é menor que Int64.MinValue ou é maior que Int64.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em Int64 valores . Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do Int64 tipo de dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CLng no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como essa operação define uma conversão de restrição, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de Int64 dados.

Aplica-se a

Explicit(BigInteger to Int16)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um objeto BigInteger em um valor inteiro com sinal de 16 bits.

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

Parâmetros

value
BigInteger

O valor a ser convertido em um inteiro com sinal de 16 bits.

Retornos

Um objeto que contém o valor do parâmetro value.

Exceções

value é menor que Int16.MinValue ou é maior que Int16.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em Int16 valores . Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do Int16 tipo de dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CShort no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como essa operação define uma conversão de restrição, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de Int16 dados. Não haverá perda de precisão no valor resultante Int16 se a conversão for bem-sucedida.

Aplica-se a

Explicit(BigInteger to Int128)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Converte explicitamente um inteiro grande em um Int128 valor.

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

Parâmetros

value
BigInteger

O valor a ser convertido.

Retornos

value convertido em Int128 valor.

Aplica-se a

Explicit(BigInteger to Half)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Converte explicitamente um inteiro grande em um Half valor.

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

Parâmetros

value
BigInteger

O valor a ser convertido.

Retornos

value convertido em Half valor.

Aplica-se a

Explicit(BigInteger to Double)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um objeto BigInteger em um valor 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

Parâmetros

value
BigInteger

O valor a ser convertido para um Double.

Retornos

Um objeto que contém o valor do parâmetro value.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em Double valores .

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CDbl no Visual Basic) for usado.

Como o BigInteger valor pode estar fora do intervalo do tipo de Double dados, essa operação é uma conversão de restrição. Se a conversão não for bem-sucedida, ela não gerará um OverflowException. Em vez disso, se o BigInteger valor for menor que Double.MinValue, o valor resultante Double será Double.NegativeInfinity. Se o BigInteger valor for maior que Double.MaxValue, o valor resultante Double será Double.PositiveInfinity.

A conversão de um BigInteger em um Double pode envolver uma perda de precisão. Em alguns casos, a perda de precisão pode fazer com que a operação de conversão ou conversão seja bem-sucedida mesmo que o BigInteger valor esteja fora do intervalo do tipo de Double dados. O exemplo a seguir ilustra esse cenário. Ele atribui o valor máximo de a Double duas BigInteger variáveis, incrementa uma BigInteger variável em 9,999e291 e testa as duas variáveis quanto à igualdade. Conforme esperado, a chamada para o BigInteger.Equals(BigInteger) método mostra que eles são desiguais. No entanto, a conversão do valor maior BigInteger de volta para um Double é bem-sucedida, embora o BigInteger valor agora exceda Double.MaxValue.

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

Aplica-se a

Explicit(BigInteger to Decimal)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um objeto BigInteger em um valor 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

Parâmetros

value
BigInteger

O valor a ser convertido para um Decimal.

Retornos

Um objeto que contém o valor do parâmetro value.

Exceções

value é menor que Decimal.MinValue ou maior que Decimal.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em Decimal valores . Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do Decimal tipo de dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CDec no Visual Basic) for usado.

Como essa operação define uma conversão de restrição, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de Decimal dados.

Aplica-se a

Explicit(BigInteger to Char)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Converte explicitamente um inteiro grande em um Char valor.

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

Parâmetros

value
BigInteger

O valor a ser convertido.

Retornos

value convertido em Char valor.

Aplica-se a

Explicit(BigInteger to Byte)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um objeto BigInteger em um valor de byte sem sinal.

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

Parâmetros

value
BigInteger

O valor a ser convertido para um Byte.

Retornos

Um objeto que contém o valor do parâmetro value.

Exceções

value é menor que Byte.MinValue ou maior que Byte.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em Byte valores . Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do Byte tipo de dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CByte no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como essa operação define uma conversão de restrição, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de Byte dados. Não haverá perda de precisão no valor resultante Byte se a conversão for bem-sucedida.

Aplica-se a

Explicit(Half to BigInteger)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Converte explicitamente um Half valor em um inteiro grande.

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

Parâmetros

value
Half

O valor a ser convertido.

Retornos

value convertido em um inteiro grande.

Aplica-se a

Explicit(Double to BigInteger)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um valor Double para um valor 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

Parâmetros

value
Double

O valor a ser convertido para um BigInteger.

Retornos

Um objeto que contém o valor do parâmetro value.

Exceções

Exemplos

O exemplo a seguir converte os elementos individuais em uma matriz de Double valores em BigInteger objetos e exibe o resultado de cada conversão. Observe que qualquer parte fracionária de um Double valor é truncada durante a conversão.

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

Comentários

Qualquer parte fracionária do value parâmetro é truncada antes da conversão.

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Como a conversão de Double para BigInteger pode envolver truncamento de qualquer parte fracionária do value, os compiladores de linguagem não executam essa conversão automaticamente. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Para idiomas que não dão suporte a operadores personalizados, o método alternativo é BigInteger.BigInteger(Double).

Aplica-se a

Explicit(Decimal to BigInteger)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um objeto Decimal em um valor 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

Parâmetros

value
Decimal

O valor a ser convertido para um BigInteger.

Retornos

Um objeto que contém o valor do parâmetro value.

Exemplos

O exemplo a seguir converte os elementos individuais em uma matriz de Decimal valores em BigInteger objetos e exibe o resultado de cada conversão. Observe que qualquer parte fracionária de um Decimal valor é truncada durante a conversão.

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

Comentários

Qualquer parte fracionária do value parâmetro é truncada antes da conversão.

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Como a conversão de Decimal para BigInteger pode envolver truncamento de qualquer parte fracionária do value, os compiladores de linguagem não executam essa conversão automaticamente. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Para idiomas que não dão suporte a operadores personalizados, o método alternativo é BigInteger.BigInteger(Decimal).

Aplica-se a

Explicit(BigInteger to Int32)

Origem:
BigInteger.cs
Origem:
BigInteger.cs
Origem:
BigInteger.cs

Define uma conversão explícita de um objeto BigInteger para um valor inteiro com sinal de 32 bits.

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

Parâmetros

value
BigInteger

O valor a ser convertido em um inteiro com sinal de 32 bits.

Retornos

Um objeto que contém o valor do parâmetro value.

Exceções

value é menor que Int32.MinValue ou é maior que Int32.MaxValue.

Exemplos

O exemplo a seguir ilustra a conversão de BigInteger em Int32 valores . Ele também manipula um OverflowException que é gerado porque o BigInteger valor está fora do intervalo do Int32 tipo de dados.

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

Comentários

As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou de onde um BigInteger objeto pode ser convertido. Os compiladores de linguagem não executam essa conversão automaticamente porque ela pode envolver perda de dados. Em vez disso, eles executam a conversão somente se um operador de conversão (em C#) ou uma função de conversão (como CType ou CInt no Visual Basic) for usado. Caso contrário, eles exibem um erro do compilador.

Como essa operação define uma conversão de restrição, ela pode gerar um em tempo de execução OverflowException se o BigInteger valor estiver fora do intervalo do tipo de Int32 dados. Não haverá perda de precisão no valor resultante Int32 se a conversão for bem-sucedida.

Aplica-se a