# BigInteger.Explicit 运算符

## 重载

 Explicit(Decimal to BigInteger) 定义从 Decimal 对象到 BigInteger 值的显式转换。Defines an explicit conversion of a Decimal object to a BigInteger value. Explicit(Double to BigInteger) 定义从 Double 值到 BigInteger 值的显式转换。Defines an explicit conversion of a Double value to a BigInteger value. Explicit(BigInteger to Byte) 定义从 BigInteger 对象到无符号字节值的显式转换。Defines an explicit conversion of a BigInteger object to an unsigned byte value. Explicit(BigInteger to Decimal) 定义从 BigInteger 对象到 Decimal 值的显式转换。Defines an explicit conversion of a BigInteger object to a Decimal value. Explicit(BigInteger to Double) 定义从 BigInteger 对象到 Double 值的显式转换。Defines an explicit conversion of a BigInteger object to a Double value. Explicit(BigInteger to Int16) 定义从 BigInteger 对象到 16 位带符号整数值的显式转换。Defines an explicit conversion of a BigInteger object to a 16-bit signed integer value. Explicit(BigInteger to Int32) 定义从 BigInteger 对象到 32 位带符号整数值的显式转换。Defines an explicit conversion of a BigInteger object to a 32-bit signed integer value. Explicit(BigInteger to Int64) 定义从 BigInteger 对象到 64 位带符号整数值的显式转换。Defines an explicit conversion of a BigInteger object to a 64-bit signed integer value. Explicit(BigInteger to SByte) 定义从 BigInteger 对象到 8 位带符号值的显式转换。Defines an explicit conversion of a BigInteger object to a signed 8-bit value. 此 API 不兼容 CLS。This API is not CLS-compliant. 符合的替代方法是 Int16。The compliant alternative is Int16. Explicit(BigInteger to Single) 定义从 BigInteger 对象到单精度浮点值的显式转换。Defines an explicit conversion of a BigInteger object to a single-precision floating-point value. Explicit(BigInteger to UInt16) 定义从 BigInteger 对象到 16 位无符号整数值的显式转换。Defines an explicit conversion of a BigInteger object to an unsigned 16-bit integer value. 此 API 不兼容 CLS。This API is not CLS-compliant. 符合的替代方法是 Int32。The compliant alternative is Int32. Explicit(BigInteger to UInt32) 定义从 BigInteger 对象到 32 位无符号整数值的显式转换。Defines an explicit conversion of a BigInteger object to an unsigned 32-bit integer value. 此 API 不兼容 CLS。This API is not CLS-compliant. 符合的替代方法是 Int64。The compliant alternative is Int64. Explicit(BigInteger to UInt64) 定义从 BigInteger 对象到 64 位无符号整数值的显式转换。Defines an explicit conversion of a BigInteger object to an unsigned 64-bit integer value. 此 API 不兼容 CLS。This API is not CLS-compliant. 符合的替代方法是 Double。The compliant alternative is Double. Explicit(Single to BigInteger) 定义从 Single 值到 BigInteger 值的显式转换。Defines an explicit conversion of a Single value to a BigInteger value.

## Explicit(Decimal to 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``

value
Decimal

### 示例

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

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 由于从 DecimalBigInteger 的转换可能涉及截断 `value`的任何小数部分，因此语言编译器不会自动执行此转换。Because the conversion from Decimal to BigInteger can involve truncating any fractional part of `value`, language compilers do not perform this conversion automatically. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 Visual Basic 中的 `CType`）时，它们才会执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(Double to 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``

value
Double

#### 异常

`value`NaNPositiveInfinityNegativeInfinity`value` is NaN, PositiveInfinity, or NegativeInfinity.

### 示例

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

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 由于从 DoubleBigInteger 的转换可能涉及截断 `value`的任何小数部分，因此语言编译器不会自动执行此转换。Because the conversion from Double to BigInteger can involve truncating any fractional part of `value`, language compilers do not perform this conversion automatically. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 Visual Basic 中的 `CType`）时，它们才会执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(BigInteger to Byte)

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

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or greater than MaxValue.

### 示例

``````// BigInteger to Byte conversion.
BigInteger goodByte = BigInteger.One;

byte byteFromBigInteger;

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

// Handle conversion that should result in overflow.
try
{
Console.WriteLine(byteFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n   {1}",
}
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
Console.WriteLine(byteFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CByte` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CByte` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(BigInteger to 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``

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or greater than MaxValue.

### 示例

``````// BigInteger to Decimal conversion.
BigInteger goodDecimal = 761652543;

Decimal decimalFromBigInteger;

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

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

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
Console.WriteLine(decimalFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CDec` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CDec` in Visual Basic) is used.

## Explicit(BigInteger to 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``

value
BigInteger

### 示例

``````// BigInteger to Double conversion.
BigInteger goodDouble = (BigInteger) 102.43e22;

double doubleFromBigInteger;

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

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

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.
Console.WriteLine(doubleFromBigInteger)
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CDbl` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CDbl` in Visual Basic) is used.

BigIntegerDouble 的转换可能会导致精度损失。The conversion of a BigInteger to a Double may involve a loss of precision. 在某些情况下，丢失精度可能导致强制转换或转换操作成功，即使 BigInteger 值超出 Double 数据类型的范围。In some cases, the loss of precision may cause the casting or conversion operation to succeed even if the BigInteger value is outside the range of the Double data type. 下例对此进行了说明。The following example provides an illustration. 它将 Double 的最大值分配给两个 BigInteger 变量，通过 9.999 e291 增加一个 BigInteger 变量，并测试这两个变量是否相等。It assigns the maximum value of a Double to two BigInteger variables, increments one BigInteger variable by 9.999e291, and tests the two variables for equality. 与预期一样，对 BigInteger.Equals(BigInteger) 方法的调用显示它们不相等。As expected, the call to the BigInteger.Equals(BigInteger) method shows that they are unequal. 但是，虽然 BigInteger 值现在超出 Double.MaxValue，但将较大的 BigInteger 值转换回 Double 会成功。However, the conversion of the larger BigInteger value back to a Double succeeds, although the BigInteger value now exceeds 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
``````

## Explicit(BigInteger to Int16)

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

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or is greater than MaxValue.

### 示例

``````// BigInteger to Int16 conversion.
BigInteger goodShort = 20000;

short shortFromBigInteger;

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

// Handle conversion that should result in overflow.
try
{
Console.WriteLine(shortFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n   {1}",
}
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
Console.WriteLine(shortFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CShort` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CShort` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(BigInteger to Int32)

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

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or is greater than MaxValue.

### 示例

``````// BigInteger to Int32 conversion.
BigInteger goodInteger = 200000;

int integerFromBigInteger;

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

// Handle conversion that should result in overflow.
try
{
Console.WriteLine(integerFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n   {1}",
}
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
Console.WriteLine(integerFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CInt` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CInt` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(BigInteger to Int64)

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

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or is greater than MaxValue.

### 示例

``````// BigInteger to Int64 conversion.
BigInteger goodLong = 2000000000;

long longFromBigInteger;

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

// Handle conversion that should result in overflow.
try
{
Console.WriteLine(longFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n   {1}",
}
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
Console.WriteLine(longFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CLng` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CLng` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(BigInteger to SByte)

System.Int16

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

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or is greater than MaxValue.

### 示例

``````// BigInteger to SByte conversion.
BigInteger goodSByte = BigInteger.MinusOne;

sbyte sByteFromBigInteger;

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

// Handle conversion that should result in overflow.
try
{
Console.WriteLine(sByteFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n   {1}",
}
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
Console.WriteLine(sByteFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CSByte` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CSByte` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(BigInteger to Single)

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

value
BigInteger

### 示例

``````// BigInteger to Single conversion.
BigInteger goodSingle = (BigInteger) 102.43e22F;

float singleFromBigInteger;

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

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

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.
Console.WriteLine(singleFromBigInteger)
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为它可能涉及到数据丢失或精度损失。Language compilers do not perform this conversion automatically because it can involve data loss or a loss of precision. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CSng` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CSng` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

BigIntegerSingle 的转换可能会导致精度损失。The conversion of a BigInteger to a Single may involve a loss of precision. 在某些情况下，丢失精度可能导致强制转换或转换操作成功，即使 BigInteger 值超出 Single 数据类型的范围。In some cases, the loss of precision may cause the casting or conversion operation to succeed even if the BigInteger value is outside the range of the Single data type. 下例对此进行了说明。The following example provides an illustration. 它将 Single 的最大值分配给两个 BigInteger 变量，通过 9.999 e291 增加一个 BigInteger 变量，并测试这两个变量是否相等。It assigns the maximum value of a Single to two BigInteger variables, increments one BigInteger variable by 9.999e291, and tests the two variables for equality. 与预期一样，对 BigInteger.Equals(BigInteger) 方法的调用显示它们不相等。As expected, the call to the BigInteger.Equals(BigInteger) method shows that they are unequal. 但是，虽然 BigInteger 值现在超出 Single.MaxValue，但将较大的 BigInteger 值转换回 Single 会成功。However, the conversion of the larger BigInteger value back to a Single succeeds, although the BigInteger value now exceeds 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
``````

## Explicit(BigInteger to UInt16)

System.Int32

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

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or is greater than MaxValue.

### 示例

``````// BigInteger to UInt16 conversion.
BigInteger goodUShort = 20000;

ushort uShortFromBigInteger;

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

// Handle conversion that should result in overflow.
try
{
Console.WriteLine(uShortFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n   {1}",
}
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
Console.WriteLine(uShortFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CUShort` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CUShort` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(BigInteger to UInt32)

System.Int64

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

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or is greater than MaxValue.

### 示例

``````// BigInteger to UInt32 conversion.
BigInteger goodUInteger = 200000;

uint uIntegerFromBigInteger;

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

// Handle conversion that should result in overflow.
try
{
Console.WriteLine(uIntegerFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n   {1}",
}
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
Console.WriteLine(uIntegerFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CUInt` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CUInt` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(BigInteger to UInt64)

System.Double

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

value
BigInteger

#### 异常

`value` 小于 MinValue 或大于 MaxValue`value` is less than MinValue or is greater than MaxValue.

### 示例

``````// BigInteger to UInt64 conversion.
BigInteger goodULong = 2000000000;

ulong uLongFromBigInteger;

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

// Handle conversion that should result in overflow.
try
{
Console.WriteLine(uLongFromBigInteger);
}
catch (OverflowException e)
{
Console.WriteLine("Unable to convert {0}:\n   {1}",
}
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
Console.WriteLine(uLongFromBigInteger)
Catch e As OverflowException
Console.WriteLine("Unable to convert {0}:{1}   {2}", _
End Try
Console.WriteLine()
``````

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 语言编译器不会自动执行此转换，因为这可能会导致数据丢失。Language compilers do not perform this conversion automatically because it can involve data loss. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 `CType``CULng` 在 Visual Basic 中）时，它们才执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` or `CULng` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.

## Explicit(Single to 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``

value
Single

#### 异常

`value`NaNPositiveInfinityNegativeInfinity`value` is NaN, PositiveInfinity, or NegativeInfinity.

### 示例

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

### 注解

Explicit(Decimal to BigInteger) 方法的重载定义可以从中转换 BigInteger 对象的类型。The overloads of the Explicit(Decimal to BigInteger) method define the types to which or from which a BigInteger object can be converted. 由于从 SingleBigInteger 的转换可能涉及截断 `value`的任何小数部分，因此语言编译器不会自动执行此转换。Because the conversion from Single to BigInteger can involve truncating any fractional part of `value`, language compilers do not perform this conversion automatically. 相反，仅当使用强制转换运算符（在中C#）或转换函数（如 Visual Basic 中的 `CType`）时，它们才会执行转换。Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as `CType` in Visual Basic) is used. 否则，它们会显示编译器错误。Otherwise, they display a compiler error.