BigInteger.Explicit 演算子

定義

BigInteger オブジェクトと別の型の間の明示的な変換を定義します。

オーバーロード

Explicit(BigInteger to SByte)

BigInteger オブジェクトから符号付き 8 ビット値への明示的な変換を定義します。

この API は、CLS に準拠していません。 準拠している代替として Int16.を使用できます。

Explicit(Single to BigInteger)

Single 値から BigInteger 値への明示的な変換を定義します。

Explicit(Complex to BigInteger)

値を Complex 大きな整数に明示的に変換します。

Explicit(BigInteger to UIntPtr)

ビッグ整数を値に明示的に UIntPtr 変換します。

Explicit(BigInteger to UInt64)

BigInteger オブジェクトから符号なし 64 ビット整数値への明示的な変換を定義します。

この API は、CLS に準拠していません。 準拠している代替として Double.を使用できます。

Explicit(BigInteger to UInt32)

BigInteger オブジェクトから符号なし 32 ビット整数値への明示的な変換を定義します。

この API は、CLS に準拠していません。 準拠している代替として Int64.を使用できます。

Explicit(BigInteger to UInt16)

BigInteger オブジェクトから符号なし 16 ビット整数値への明示的な変換を定義します。

この API は、CLS に準拠していません。 準拠している代替として Int32.を使用できます。

Explicit(BigInteger to UInt128)

ビッグ整数を値に明示的に UInt128 変換します。

Explicit(BigInteger to Single)

BigInteger オブジェクトから単精度浮動小数点値への明示的な変換を定義します。

Explicit(BigInteger to IntPtr)

ビッグ整数を値に明示的に IntPtr 変換します。

Explicit(BigInteger to Int64)

BigInteger オブジェクトから 64 ビット符号付き整数値への明示的な変換を定義します。

Explicit(BigInteger to Int16)

BigInteger オブジェクトから 16 ビット符号付き整数値への明示的な変換を定義します。

Explicit(BigInteger to Int128)

ビッグ整数を値に明示的に Int128 変換します。

Explicit(BigInteger to Half)

ビッグ整数を値に明示的に Half 変換します。

Explicit(BigInteger to Double)

BigInteger オブジェクトから Double 値への明示的な変換を定義します。

Explicit(BigInteger to Decimal)

BigInteger オブジェクトから Decimal 値への明示的な変換を定義します。

Explicit(BigInteger to Char)

ビッグ整数を値に明示的に Char 変換します。

Explicit(BigInteger to Byte)

BigInteger オブジェクトから符号なしバイト値への明示的な変換を定義します。

Explicit(Half to BigInteger)

値を Half 大きな整数に明示的に変換します。

Explicit(Double to BigInteger)

Double 値から BigInteger 値への明示的な変換を定義します。

Explicit(Decimal to BigInteger)

Decimal オブジェクトから BigInteger 値への明示的な変換を定義します。

Explicit(BigInteger to Int32)

BigInteger オブジェクトから 32 ビット符号付き整数値への明示的な変換を定義します。

Explicit(BigInteger to SByte)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Int16

BigInteger オブジェクトから符号付き 8 ビット値への明示的な変換を定義します。

この API は、CLS に準拠していません。 準拠している代替として 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

パラメーター

value
BigInteger

符号付き 8 ビット値へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

属性

例外

valueSByte.MinValue より小さいか、 SByte.MaxValue より大きい。

次の例は、 から 値への変換をBigIntegerSByte示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もSByte処理OverflowExceptionします。

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

sbyte sByteFromBigInteger;

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

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

Dim sByteFromBigInteger As SByte

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 言語コンパイラでは、データが失われる可能性があるため、この変換は自動的には実行されません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic などCTypeCSByte) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をSByteスローOverflowExceptionできます。 変換が成功した場合、結果 SByte の値の精度は失われません。

適用対象

Explicit(Single to BigInteger)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

Single 値から 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

BigInteger へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

例外

valueNaNPositiveInfinity、または NegativeInfinity です。

次の例では、値の配列内の個々の Single 要素を オブジェクトに BigInteger 変換し、各変換の結果を表示します。 値の Single 小数部は、変換中に切り捨てられることに注意してください。

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

注釈

パラメーターの value 小数部は、変換前に切り捨てられます。

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 から Single への BigInteger 変換には、 の小数部の value切り捨てが必要な場合があるため、言語コンパイラはこの変換を自動的に実行しません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic など CType ) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

カスタム演算子をサポートしていない言語の場合、代替メソッドは です BigInteger.BigInteger(Single)

適用対象

Explicit(Complex to BigInteger)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

値を Complex 大きな整数に明示的に変換します。

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

パラメーター

value
Complex

変換する値。

戻り値

value 大きな整数に変換されます。

適用対象

Explicit(BigInteger to UIntPtr)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

重要

この API は CLS 準拠ではありません。

ビッグ整数を値に明示的に UIntPtr 変換します。

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

パラメーター

value
BigInteger

変換する値。

戻り値

UIntPtr

unativeint

value は value に UIntPtr 変換されます。

属性

適用対象

Explicit(BigInteger to UInt64)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Double

BigInteger オブジェクトから符号なし 64 ビット整数値への明示的な変換を定義します。

この API は、CLS に準拠していません。 準拠している代替として 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

パラメーター

value
BigInteger

符号なし 64 ビット整数へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

属性

例外

valueUInt64.MinValue より小さいか、 UInt64.MaxValue より大きい。

次の例は、 から 値への変換をBigIntegerUInt64示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もUInt64処理OverflowExceptionします。

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

ulong uLongFromBigInteger;

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

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

Dim uLongFromBigInteger As ULong

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 言語コンパイラでは、データが失われる可能性があるため、この変換は自動的には実行されません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic などCTypeCULng) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をUInt64スローOverflowExceptionできます。 変換が成功した場合、結果 UInt64 の値の精度は失われません。

適用対象

Explicit(BigInteger to UInt32)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Int64

BigInteger オブジェクトから符号なし 32 ビット整数値への明示的な変換を定義します。

この API は、CLS に準拠していません。 準拠している代替として 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

パラメーター

value
BigInteger

符号なし 32 ビット整数へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

属性

例外

valueUInt32.MinValue より小さいか、 UInt32.MaxValue より大きい。

次の例は、 から 値への変換をBigIntegerUInt32示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もUInt32処理OverflowExceptionします。

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

uint uIntegerFromBigInteger;

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

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

Dim uIntegerFromBigInteger As UInteger

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 言語コンパイラでは、データが失われる可能性があるため、この変換は自動的には実行されません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic などCTypeCUInt) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をUInt32スローOverflowExceptionできます。 変換が成功した場合、結果 UInt32 の値の精度は失われません。

適用対象

Explicit(BigInteger to UInt16)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

重要

この API は CLS 準拠ではありません。

CLS 準拠の代替
System.Int32

BigInteger オブジェクトから符号なし 16 ビット整数値への明示的な変換を定義します。

この API は、CLS に準拠していません。 準拠している代替として 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

パラメーター

value
BigInteger

符号なし 16 ビット整数へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

属性

例外

valueUInt16.MinValue より小さいか、 UInt16.MaxValue より大きい。

次の例は、 から 値への変換をBigIntegerUInt16示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もUInt16処理OverflowExceptionします。

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

ushort uShortFromBigInteger;

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

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

Dim uShortFromBigInteger As UShort

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 言語コンパイラでは、データが失われる可能性があるため、この変換は自動的には実行されません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic などCTypeCUShort) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をUInt16スローOverflowExceptionできます。 変換が成功した場合、結果 UInt16 の値の精度は失われません。

適用対象

Explicit(BigInteger to UInt128)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

重要

この API は CLS 準拠ではありません。

ビッグ整数を値に明示的に UInt128 変換します。

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

パラメーター

value
BigInteger

変換する値。

戻り値

value は value に UInt128 変換されます。

属性

適用対象

Explicit(BigInteger to Single)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

BigInteger オブジェクトから単精度浮動小数点値への明示的な変換を定義します。

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

単精度浮動小数点値へと変換する値。

戻り値

value パラメーターの値にできるだけ近い値となるように変換したオブジェクト。

次の例は、 から 値への変換をBigIntegerSingle示しています。

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

float singleFromBigInteger;

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

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

Dim singleFromBigInteger As Single

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 言語コンパイラは、データの損失や精度の低下を伴う可能性があるため、この変換を自動的に実行しません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic などCTypeCSng) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

値が BigInteger データ型の Single 範囲外になる可能性があるため、この操作は縮小変換です。 変換が失敗した場合、 はスロー OverflowExceptionされません。 代わりに、値が BigInteger より Single.MinValue小さい場合、結果 Single の値は になります Single.NegativeInfinity。 値が BigInteger より Single.MaxValue大きい場合、結果 Single の値は になります Single.PositiveInfinity

へのBigIntegerSingle変換には、精度の低下が伴う場合があります。 場合によっては、有効桁数が失われると、値がデータ型の範囲外であっても BigInteger 、キャストまたは変換操作が成功する Single 可能性があります。 具体的な例を次に示します。 2 つの変数に の最大値をSingle割り当て、1 つのBigIntegerBigInteger変数を 9.999e291 ずつインクリメントし、2 つの変数の等価性をテストします。 予想どおり、 メソッドの BigInteger.Equals(BigInteger) 呼び出しは、それらが等しくないことを示しています。 ただし、大きな BigInteger 値を に Single 戻す変換は成功しますが、値は BigInteger を超えています 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 IntPtr)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

ビッグ整数を値に明示的に IntPtr 変換します。

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

パラメーター

value
BigInteger

変換する値。

戻り値

IntPtr

nativeint

value は value に IntPtr 変換されます。

適用対象

Explicit(BigInteger to Int64)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

BigInteger オブジェクトから 64 ビット符号付き整数値への明示的な変換を定義します。

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

64 ビット符号付き整数へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

例外

valueInt64.MinValue より小さいか、 Int64.MaxValue より大きい。

次の例は、 から 値への変換をBigIntegerInt64示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もInt64処理OverflowExceptionします。

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

long longFromBigInteger;

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

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

Dim longFromBigInteger As Long

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 言語コンパイラでは、データが失われる可能性があるため、この変換は自動的には実行されません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic などCTypeCLng) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をInt64スローOverflowExceptionできます。

適用対象

Explicit(BigInteger to Int16)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

BigInteger オブジェクトから 16 ビット符号付き整数値への明示的な変換を定義します。

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

16 ビット符号付き整数へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

例外

valueInt16.MinValue より小さいか、 Int16.MaxValue より大きい。

次の例は、 から 値への変換をBigIntegerInt16示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もInt16処理OverflowExceptionします。

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

short shortFromBigInteger;

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

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

Dim shortFromBigInteger As Short

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 言語コンパイラでは、データが失われる可能性があるため、この変換は自動的には実行されません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic などCTypeCShort) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をInt16スローOverflowExceptionできます。 変換が成功した場合、結果 Int16 の値の精度は失われません。

適用対象

Explicit(BigInteger to Int128)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

ビッグ整数を値に明示的に Int128 変換します。

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

パラメーター

value
BigInteger

変換する値。

戻り値

value は value に Int128 変換されます。

適用対象

Explicit(BigInteger to Half)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

ビッグ整数を値に明示的に Half 変換します。

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

パラメーター

value
BigInteger

変換する値。

戻り値

value は value に Half 変換されます。

適用対象

Explicit(BigInteger to Double)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

BigInteger オブジェクトから 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

Double へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

次の例は、 から 値への変換をBigIntegerDouble示しています。

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

double doubleFromBigInteger;

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

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

Dim doubleFromBigInteger As Double

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換先または変換元となる型を BigInteger 定義します。 言語コンパイラでは、データが失われる可能性があるため、この変換は自動的には実行されません。 代わりに、キャスト演算子 (C#) または変換関数 ( CTypeCDbl Visual Basic など) が使用されている場合にのみ、変換を実行します。

値が BigInteger データ型の Double 範囲外になる可能性があるため、この操作は縮小変換です。 変換が失敗した場合、 はスロー OverflowExceptionされません。 代わりに、値が BigInteger より Double.MinValue小さい場合、結果 Double の値は になります Double.NegativeInfinity。 値が BigInteger より Double.MaxValue大きい場合、結果 Double の値は になります Double.PositiveInfinity

BigIntegerDouble 変換すると、精度が失われる可能性があります。 値がデータ型の範囲外であっても BigInteger 、精度が失われるとキャストまたは変換操作が成功する Double 場合があります。 具体的な例を次に示します。 2 つのBigInteger変数に の最大値をDouble割り当て、1 つのBigInteger変数を 9.999e291 ずつインクリメントし、2 つの変数の等価性をテストします。 予想どおり、 メソッドの BigInteger.Equals(BigInteger) 呼び出しは、それらが等しくないことを示しています。 ただし、大きな BigInteger 値を に戻す Double 変換は成功しますが、値は BigInteger を超えています 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 Decimal)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

BigInteger オブジェクトから 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

Decimal へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

例外

valueDecimal.MinValue より小さいか、 Decimal.MaxValue より大きい。

次の例は、 から 値への変換 BigIntegerDecimal 示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もDecimal処理OverflowExceptionします。

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

Decimal decimalFromBigInteger;

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

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

Dim decimalFromBigInteger As Decimal

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換元または変換元となる型を BigInteger 定義します。 言語コンパイラは、データ損失を伴う可能性があるため、この変換を自動的に実行しません。 代わりに、キャスト演算子 (C#) または変換関数 ( CTypeCDec Visual Basic など) が使用されている場合にのみ、変換を実行します。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をDecimalスローOverflowExceptionできます。

適用対象

Explicit(BigInteger to Char)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

大きな整数を値に明示的に Char 変換します。

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

パラメーター

value
BigInteger

変換する値。

戻り値

value 値に Char 変換されます。

適用対象

Explicit(BigInteger to Byte)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

BigInteger オブジェクトから符号なしバイト値への明示的な変換を定義します。

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

Byte へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

例外

valueByte.MinValue より小さいか 、Byte.MaxValue より大きい。

次の例は、 から 値への変換 BigIntegerByte 示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もByte処理OverflowExceptionします。

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

byte byteFromBigInteger;

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

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

Dim byteFromBigInteger As Byte   

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換元または変換元となる型を BigInteger 定義します。 言語コンパイラは、データ損失を伴う可能性があるため、この変換を自動的に実行しません。 代わりに、キャスト演算子 (C#) または変換関数 ( CTypeCByte Visual Basic など) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をByteスローOverflowExceptionできます。 変換が成功した場合、結果 Byte の値の精度は失われません。

適用対象

Explicit(Half to BigInteger)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

値を Half 大きな整数に明示的に変換します。

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

パラメーター

value
Half

変換する値。

戻り値

value は大きな整数に変換されます。

適用対象

Explicit(Double to BigInteger)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

Double 値から 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

BigInteger へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

例外

valueNaNPositiveInfinity、または NegativeInfinity です。

次の例では、値の配列内の個々の Double 要素を オブジェクトに BigInteger 変換し、各変換の結果を表示します。 値の Double 小数部は、変換中に切り捨てられることに注意してください。

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

注釈

パラメーターの value 小数部は、変換前に切り捨てられます。

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換元または変換元となる型を BigInteger 定義します。 から Double への BigInteger 変換には、 の小数部 valueの切り捨てが含まれる可能性があるため、言語コンパイラはこの変換を自動的に実行しません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic など CType ) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

カスタム演算子をサポートしていない言語の場合、代替メソッドは です BigInteger.BigInteger(Double)

適用対象

Explicit(Decimal to BigInteger)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

Decimal オブジェクトから 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

BigInteger へと変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

次の例では、値の配列内の個々の Decimal 要素を オブジェクトに BigInteger 変換し、各変換の結果を表示します。 値の 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

注釈

パラメーターの value 小数部は、変換前に切り捨てられます。

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換元または変換元となる型を BigInteger 定義します。 から Decimal への BigInteger 変換には、 の小数部 valueの切り捨てが含まれる可能性があるため、言語コンパイラはこの変換を自動的に実行しません。 代わりに、キャスト演算子 (C#) または変換関数 (Visual Basic など CType ) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

カスタム演算子をサポートしていない言語の場合、代替メソッドは です BigInteger.BigInteger(Decimal)

適用対象

Explicit(BigInteger to Int32)

ソース:
BigInteger.cs
ソース:
BigInteger.cs
ソース:
BigInteger.cs

BigInteger オブジェクトから 32 ビット符号付き整数値への明示的な変換を定義します。

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

32 ビット符号付き整数に変換する値。

戻り値

value パラメーターの値を格納しているオブジェクト。

例外

valueInt32.MinValue より小さいか、 Int32.MaxValue より大きい。

次の例は、 から 値への変換 BigIntegerInt32 示しています。 また、値がデータ型の範囲外であるためにBigIntegerスローされる もInt32処理OverflowExceptionします。

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

int integerFromBigInteger;

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

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

Dim integerFromBigInteger As Integer

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

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

注釈

メソッドのオーバーロードは、 Explicit(Decimal to BigInteger) オブジェクトの変換元または変換元となる型を BigInteger 定義します。 言語コンパイラは、データ損失を伴う可能性があるため、この変換を自動的に実行しません。 代わりに、キャスト演算子 (C#) または変換関数 ( CTypeCInt Visual Basic など) が使用されている場合にのみ、変換を実行します。 それ以外の場合は、コンパイラ エラーが表示されます。

この操作は縮小変換を定義するため、値がデータ型の範囲外の場合BigInteger、実行時に をInt32スローOverflowExceptionできます。 変換が成功した場合、結果 Int32 の値の精度は失われません。

適用対象