BigInteger.Explicit Operador
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Define uma conversão explícita entre um BigInteger objeto e outro tipo.
Sobrecargas
| Name | Description |
|---|---|
| Explicit(Decimal to BigInteger) |
Define uma conversão explícita de um Decimal objeto num BigInteger valor. |
| Explicit(Double to BigInteger) |
Define uma conversão explícita de um Double valor para um BigInteger valor. |
| Explicit(BigInteger to Byte) |
Define uma conversão explícita de um BigInteger objeto para um valor de byte sem sinal. |
| Explicit(BigInteger to Decimal) |
Define uma conversão explícita de um BigInteger objeto num Decimal valor. |
| Explicit(BigInteger to Double) |
Define uma conversão explícita de um BigInteger objeto num Double valor. |
| Explicit(BigInteger to Int16) |
Define uma conversão explícita de um BigInteger objeto para um valor inteiro assinado de 16 bits. |
| Explicit(BigInteger to Int32) |
Define uma conversão explícita de um BigInteger objeto para um valor inteiro assinado de 32 bits. |
| Explicit(BigInteger to Int64) |
Define uma conversão explícita de um BigInteger objeto para um valor inteiro assinado de 64 bits. |
| Explicit(BigInteger to SByte) |
Define uma conversão explícita de um BigInteger objeto para um valor assinado de 8 bits. Esta API não está em conformidade com CLS. A alternativa conforme é Int16. |
| Explicit(BigInteger to Single) |
Define uma conversão explícita de um BigInteger objeto para um valor de ponto flutuante de precisão simples. |
| Explicit(BigInteger to UInt16) |
Define uma conversão explícita de um BigInteger objeto para um valor inteiro de 16 bits sem sinal. Esta API não está em conformidade com CLS. A alternativa conforme é Int32. |
| Explicit(BigInteger to UInt32) |
Define uma conversão explícita de um BigInteger objeto para um valor inteiro de 32 bits sem sinal. Esta API não está em conformidade com CLS. A alternativa conforme é Int64. |
| Explicit(BigInteger to UInt64) |
Define uma conversão explícita de um BigInteger objeto para um valor inteiro não assinado de 64 bits. Esta API não está em conformidade com CLS. A alternativa conforme é Double. |
| Explicit(Single to BigInteger) |
Define uma conversão explícita de um Single valor para um BigInteger valor. |
Explicit(Decimal to BigInteger)
Define uma conversão explícita de um Decimal objeto num BigInteger valor.
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 converter para um BigInteger.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exemplos
O exemplo seguinte converte os elementos individuais de um array de Decimal valores em BigInteger objetos e depois mostra o resultado de cada conversão. Note 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
let decimals = [| Decimal.MinValue; -15632.991m; 9029321.12m; Decimal.MaxValue |]
printfn "%35s %35s\n" "Decimal" "BigInteger"
for value in decimals do
let number = BigInteger(value)
printfn "%35O %35O" 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
Observações
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 a partir dos quais um BigInteger objeto pode ser convertido. Como a conversão de Decimal para BigInteger pode envolver truncar qualquer parte fracionária de value, os compiladores de linguagem não realizam esta conversão automaticamente. Em vez disso, realizam a conversão apenas se for usado um operador de casting (em C#) ou uma função de conversão (como CType em Visual Basic). Caso contrário, apresentam um erro do compilador.
Para linguagens que não suportam operadores personalizados, o método alternativo é BigInteger.BigInteger(Decimal).
Aplica-se a
Explicit(Double to BigInteger)
Define uma conversão explícita de um Double valor para um BigInteger valor.
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 converter para um BigInteger.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exceções
value é NaN, PositiveInfinity, ou NegativeInfinity.
Exemplos
O exemplo seguinte converte os elementos individuais de um array de Double valores em BigInteger objetos e depois mostra o resultado de cada conversão. Note 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
let doubles =
[| Double.MinValue
-1.430955172e03
2.410970032e05
Double.MaxValue
Double.PositiveInfinity
Double.NegativeInfinity
Double.NaN |]
printfn "%37s %37s\n" "Double" "BigInteger"
for value in doubles do
try
let number = BigInteger(value)
printfn "%37O %37O" value number
with :? OverflowException ->
printfn "%37O %37s" 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
Observações
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 a partir dos quais um BigInteger objeto pode ser convertido. Como a conversão de Double para BigInteger pode envolver truncar qualquer parte fracionária de value, os compiladores de linguagem não realizam esta conversão automaticamente. Em vez disso, realizam a conversão apenas se for usado um operador de casting (em C#) ou uma função de conversão (como CType em Visual Basic). Caso contrário, apresentam um erro do compilador.
Para linguagens que não suportam operadores personalizados, o método alternativo é BigInteger.BigInteger(Double).
Aplica-se a
Explicit(BigInteger to Byte)
Define uma conversão explícita de um BigInteger objeto para 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 converter para um Byte.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exceções
value é menor que Byte.MinValue ou maior que Byte.MaxValue.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para Byte valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do Byte tipo de dado.
// 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.
let goodByte = BigInteger.One
let badByte = bigint 256
// Successful conversion using cast operator.
let byteFromBigInteger = byte goodByte
printfn $"{byteFromBigInteger}"
// Handle conversion that should result in overflow.
try
let byteFromBigInteger = byte badByte
printfn $"{byteFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badByte}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CByte em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do Byte tipo de dado. Não há perda de precisão no valor resultante Byte se a conversão for bem-sucedida.
Aplica-se a
Explicit(BigInteger to Decimal)
Define uma conversão explícita de um BigInteger objeto num Decimal valor.
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 converter para um Decimal.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exceções
value é menor que Valor Mínimo Decimal ou maior que ValorMáximaValor Decimal.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para Decimal valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do Decimal tipo de dado.
// 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.
let goodDecimal = 761652543
let badDecimal = bigint Decimal.MaxValue + BigInteger.One
// Successful conversion using cast operator.
let decimalFromBigInteger = decimal goodDecimal
printfn $"{decimalFromBigInteger}"
// Handle conversion that should result in overflow.
try
let decimalFromBigInteger = decimal badDecimal
printfn $"{decimalFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badDecimal}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CDec em Visual Basic).
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do Decimal tipo de dado.
Aplica-se a
Explicit(BigInteger to Double)
Define uma conversão explícita de um BigInteger objeto num Double valor.
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 converter para um Double.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para 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.
let goodDouble = bigint 102.43e22
let badDouble = bigint Double.MaxValue * bigint 2
// successful conversion using cast operator.
let doubleFromBigInteger = double goodDouble
printfn $"{doubleFromBigInteger}"
// Convert an out-of-bounds BigInteger value to a Double.
let doubleFromBigInteger = double badDouble
printfn $"{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)
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CDbl em Visual Basic).
Como o BigInteger valor pode estar fora do intervalo do Double tipo de dado, esta operação é uma conversão de estreito. Se a conversão não for bem-sucedida, não lança um OverflowException. Em vez disso, se o BigInteger valor for menor que Double.MinValue, o valor resultante Double é Double.NegativeInfinity. Se o BigInteger valor for maior que Double.MaxValue, o valor resultante Double é Double.PositiveInfinity.
A conversão de a BigInteger em a Double pode implicar uma perda de precisão. Em alguns casos, a perda de precisão pode fazer com que a operação de fundição ou conversão tenha sucesso, mesmo que o BigInteger valor esteja fora do intervalo do Double tipo de dado. O exemplo a seguir fornece uma ilustração. Atribui o valor máximo de a Double a duas BigInteger variáveis, incrementa uma BigInteger variável em 9,999e291 e testa as duas variáveis quanto à igualdade. Como esperado, a chamada ao BigInteger.Equals(BigInteger) método mostra que são desiguais. No entanto, a conversão do valor maior BigInteger de volta para a 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.
let number1 = bigint Double.MaxValue
let number2 = number1 + bigint 9.999e291
// Compare the BigInteger values for equality.
printfn $"BigIntegers equal: {number2.Equals number1}"
// Convert the BigInteger to a Double.
let dbl = float number2
// Display the two values.
printfn $"BigInteger: {number2}"
printfn $"Double: {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 Int16)
Define uma conversão explícita de um BigInteger objeto para um valor inteiro assinado 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 converter para um inteiro assinado de 16 bits.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exceções
value é menor que Int16.MinValue ou é maior que Int16.MaxValue.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para Int16 valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do Int16 tipo de dado.
// 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.
let goodShort = bigint 20000
let badShort = bigint 33000
// Successful conversion using cast operator.
let shortFromBigInteger = int16 goodShort
printfn $"{shortFromBigInteger}"
// Handle conversion that should result in overflow.
try
let shortFromBigInteger = int16 badShort
printfn $"{shortFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badShort}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CShort em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do Int16 tipo de dado. Não há perda de precisão no valor resultante Int16 se a conversão for bem-sucedida.
Aplica-se a
Explicit(BigInteger to Int32)
Define uma conversão explícita de um BigInteger objeto para um valor inteiro assinado 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 converter para um inteiro com sinal de 32 bits.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exceções
value é menor que Int32.MinValue ou é maior que Int32.MaxValue.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para Int32 valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do Int32 tipo de dado.
// 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.
let goodInteger = bigint 200000
let badInteger = bigint 65000000000L
// Successful conversion using cast operator.
let integerFromBigInteger = int goodInteger
printfn $"{integerFromBigInteger}"
// Handle conversion that should result in overflow.
try
let integerFromBigInteger = int badInteger
printfn $"{integerFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badInteger}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CInt em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do Int32 tipo de dado. Não há perda de precisão no valor resultante Int32 se a conversão for bem-sucedida.
Aplica-se a
Explicit(BigInteger to Int64)
Define uma conversão explícita de um BigInteger objeto para um valor inteiro assinado 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 converter para um inteiro com sinal de 64 bits.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exceções
value é menor que Int64.MinValue ou é maior que Int64.MaxValue.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para Int64 valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do Int64 tipo de dado.
// 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.
let goodLong = 2000000000
let badLong = BigInteger.Pow(goodLong, 3)
// Successful conversion using cast operator.
let longFromBigInteger = int64 goodLong
printfn $"{longFromBigInteger}"
// Handle conversion that should result in overflow.
try
let longFromBigInteger = int64 badLong
printfn $"{longFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badLong}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CLng em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do Int64 tipo de dado.
Aplica-se a
Explicit(BigInteger to SByte)
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 BigInteger objeto para um valor assinado de 8 bits.
Esta API não está em conformidade com CLS. A alternativa conforme é 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 converter num valor de 8 bits assinado.
Devoluções
Um objeto que contém o valor do value parâmetro.
- Atributos
Exceções
value é menor que SByte.MinValue ou é maior que SByte.MaxValue.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para SByte valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do SByte tipo de dado.
// 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.
let goodSByte = BigInteger.MinusOne
let badSByte = bigint -130
// Successful conversion using cast operator.
let sByteFromBigInteger = sbyte goodSByte
printfn $"{sByteFromBigInteger}"
// Handle conversion that should result in overflow.
try
let sByteFromBigInteger = sbyte badSByte
printfn $"{sByteFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badSByte}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CSByte em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do SByte tipo de dado. Não há perda de precisão no valor resultante SByte se a conversão for bem-sucedida.
Aplica-se a
Explicit(BigInteger to Single)
Define uma conversão explícita de um BigInteger objeto para 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 converter para um valor de ponto flutuante de precisão simples.
Devoluções
Um objeto que contém a representação mais próxima possível do value parâmetro.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para 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.
let goodSingle = bigint 102.43e22F
let badSingle = bigint Single.MaxValue * bigint 2
// Successful conversion using cast operator.
let singleFromBigInteger = float32 goodSingle
printfn $"{singleFromBigInteger}"
// Convert an out-of-bounds BigInteger value to a Single.
let singleFromBigInteger = float32 badSingle
printfn $"{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)
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados ou perda de precisão. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CSng em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como o BigInteger valor pode estar fora do intervalo do Single tipo de dado, esta operação é uma conversão de estreito. Se a conversão não for bem-sucedida, não lança um OverflowException. Em vez disso, se o BigInteger valor for menor que Single.MinValue, o valor resultante Single é Single.NegativeInfinity. Se o BigInteger valor for maior que Single.MaxValue, o valor resultante Single é Single.PositiveInfinity.
A conversão de a BigInteger em a Single pode implicar uma perda de precisão. Em alguns casos, a perda de precisão pode fazer com que a operação de fundição ou conversão tenha sucesso, mesmo que o BigInteger valor esteja fora do intervalo do Single tipo de dado. O exemplo a seguir fornece uma ilustração. Atribui o valor máximo de a Single a duas BigInteger variáveis, incrementa uma BigInteger variável em 9,999e291 e testa as duas variáveis quanto à igualdade. Como esperado, a chamada ao BigInteger.Equals(BigInteger) método mostra que são desiguais. No entanto, a conversão do valor maior BigInteger de volta para a 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.
let number1 = bigint Single.MaxValue
let number2 = number1 + bigint 9.999e30
// Compare the BigInteger values for equality.
printfn $"BigIntegers equal: {number2.Equals number1}"
// Convert the BigInteger to a Single.
let sng = float32 number2
// Display the two values.
printfn $"BigInteger: {number2}"
printfn $"Single: {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 UInt16)
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 BigInteger objeto para um valor inteiro de 16 bits sem sinal.
Esta API não está em conformidade com CLS. A alternativa conforme é 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 converter para um inteiro de 16 bits sem sinal.
Devoluções
Um objeto que contém o valor do value parâmetro.
- Atributos
Exceções
value é menor que UInt16.MinValue ou é maior que UInt16.MaxValue.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para UInt16 valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do UInt16 tipo de dado.
// 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.
let goodUShort = bigint 20000
let badUShort = bigint 66000
// Successful conversion using cast operator.
let uShortFromBigInteger = uint16 goodUShort
printfn $"{uShortFromBigInteger}"
// Handle conversion that should result in overflow.
try
let uShortFromBigInteger = uint16 badUShort
printfn $"{uShortFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badSByte}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CUShort em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do UInt16 tipo de dado. Não há perda de precisão no valor resultante UInt16 se a conversão for bem-sucedida.
Aplica-se a
Explicit(BigInteger to UInt32)
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 BigInteger objeto para um valor inteiro de 32 bits sem sinal.
Esta API não está em conformidade com CLS. A alternativa conforme é 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 converter para um inteiro não assinado de 32 bits.
Devoluções
Um objeto que contém o valor do value parâmetro.
- Atributos
Exceções
value é menor que UInt32.MinValue ou é maior que UInt32.MaxValue.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para UInt32 valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do UInt32 tipo de dado.
// 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.
let goodUInteger = bigint 200000
let badUInteger = bigint 65000000000L
// Successful conversion using cast operator.
let uIntegerFromBigInteger = uint goodInteger
printfn $"{uIntegerFromBigInteger}"
// Handle conversion that should result in overflow.
try
let uIntegerFromBigInteger = uint badUInteger
printfn $"{uIntegerFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badUInteger}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CUInt em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do UInt32 tipo de dado. Não há perda de precisão no valor resultante UInt32 se a conversão for bem-sucedida.
Aplica-se a
Explicit(BigInteger to UInt64)
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 BigInteger objeto para um valor inteiro não assinado de 64 bits.
Esta API não está em conformidade com CLS. A alternativa conforme é 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 converter para um inteiro não assinado de 64 bits.
Devoluções
Um objeto que contém o valor do value parâmetro.
- Atributos
Exceções
value é menor que UInt64.MinValue ou é maior que UInt64.MaxValue.
Exemplos
O exemplo seguinte ilustra a conversão de BigInteger para UInt64 valores. Também trata um OverflowException que é lançado porque o BigInteger valor está fora do intervalo do UInt64 tipo de dado.
// 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.
let goodULong = bigint 2000000000
let badULong = BigInteger.Pow(goodULong, 3)
// Successful conversion using cast operator.
let uLongFromBigInteger = uint64 goodULong
printfn $"{uLongFromBigInteger}"
// Handle conversion that should result in overflow.
try
let uLongFromBigInteger = uint64 badULong
printfn $"{uLongFromBigInteger}"
with :? OverflowException as e ->
printfn $"Unable to convert {badULong}:\n {e.Message}"
' 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()
Observações
As sobrecargas do Explicit(Decimal to BigInteger) método definem os tipos para os quais ou a partir dos quais um BigInteger objeto pode ser convertido. Os compiladores de linguagem não realizam esta conversão automaticamente porque pode envolver perda de dados. Em vez disso, realizam a conversão apenas se for utilizado um operador de casting (em C#) ou uma função de conversão (como CType ou CULng em Visual Basic). Caso contrário, apresentam um erro do compilador.
Como esta operação define uma conversão de estreito, pode lançar um OverflowException em tempo de execução se o BigInteger valor estiver fora do intervalo do UInt64 tipo de dado. Não há perda de precisão no valor resultante UInt64 se a conversão for bem-sucedida.
Aplica-se a
Explicit(Single to BigInteger)
Define uma conversão explícita de um Single valor para um BigInteger valor.
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 converter para um BigInteger.
Devoluções
Um objeto que contém o valor do value parâmetro.
Exceções
value é NaN, PositiveInfinity, ou NegativeInfinity.
Exemplos
O exemplo seguinte converte os elementos individuais de um array de Single valores em BigInteger objetos e depois mostra o resultado de cada conversão. Note 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
let singles =
[| Single.MinValue
-1.430955172e03f
2.410970032e05f
Single.MaxValue
Single.PositiveInfinity
Single.NegativeInfinity
Single.NaN |]
printfn "%37s %37s\n" "Single" "BigInteger"
for value in singles do
try
let number = BigInteger(value)
printfn "%37O %37O" value number
with :? OverflowException ->
printfn "%37O %37s" 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
Observações
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 a partir dos quais um BigInteger objeto pode ser convertido. Como a conversão de Single para BigInteger pode envolver truncar qualquer parte fracionária de value, os compiladores de linguagem não realizam esta conversão automaticamente. Em vez disso, realizam a conversão apenas se for usado um operador de casting (em C#) ou uma função de conversão (como CType em Visual Basic). Caso contrário, apresentam um erro do compilador.
Para linguagens que não suportam operadores personalizados, o método alternativo é BigInteger.BigInteger(Single).