BigInteger.Explicit Operator

Definicja

Definiuje jawną konwersję między obiektem a innym typem BigInteger .

Przeciążenia

Explicit(BigInteger to SByte)

Definiuje jawną konwersję BigInteger obiektu na podpisaną wartość 8-bitową.

Ten interfejs API nie jest zgodny ze specyfikacją CLS. Zgodna alternatywa to Int16.

Explicit(Single to BigInteger)

Definiuje jawną konwersję SingleBigInteger wartości na wartość.

Explicit(Complex to BigInteger)

Jawnie konwertuje Complex wartość na dużą liczbę całkowitą.

Explicit(BigInteger to UIntPtr)

Jawnie konwertuje dużą liczbę całkowitą na UIntPtr wartość.

Explicit(BigInteger to UInt64)

Definiuje jawną konwersję BigInteger obiektu na niepodpisaną wartość całkowitą 64-bitową.

Ten interfejs API nie jest zgodny ze specyfikacją CLS. Zgodna alternatywa to Double.

Explicit(BigInteger to UInt32)

Definiuje jawną konwersję BigInteger obiektu na niepodpisaną wartość całkowitą 32-bitową.

Ten interfejs API nie jest zgodny ze specyfikacją CLS. Zgodna alternatywa to Int64.

Explicit(BigInteger to UInt16)

Definiuje jawną konwersję BigInteger obiektu na niepodpisaną 16-bitową wartość całkowitą.

Ten interfejs API nie jest zgodny ze specyfikacją CLS. Zgodna alternatywa to Int32.

Explicit(BigInteger to UInt128)

Jawnie konwertuje dużą liczbę całkowitą na UInt128 wartość.

Explicit(BigInteger to Single)

Definiuje jawną konwersję BigInteger obiektu na wartość zmiennoprzecinkową o pojedynczej precyzji.

Explicit(BigInteger to IntPtr)

Jawnie konwertuje dużą liczbę całkowitą na IntPtr wartość.

Explicit(BigInteger to Int64)

Definiuje jawną konwersję BigInteger obiektu na 64-bitową wartość całkowitą ze znakiem.

Explicit(BigInteger to Int16)

Definiuje jawną konwersję BigInteger obiektu na wartość całkowitą z podpisem 16-bitowym.

Explicit(BigInteger to Int128)

Jawnie konwertuje dużą liczbę całkowitą na Int128 wartość.

Explicit(BigInteger to Half)

Jawnie konwertuje dużą liczbę całkowitą na Half wartość.

Explicit(BigInteger to Double)

Definiuje jawną konwersję BigIntegerDouble obiektu na wartość.

Explicit(BigInteger to Decimal)

Definiuje jawną konwersję BigIntegerDecimal obiektu na wartość.

Explicit(BigInteger to Char)

Jawnie konwertuje dużą liczbę całkowitą na Char wartość.

Explicit(BigInteger to Byte)

Definiuje jawną konwersję BigInteger obiektu na niepodpisaną wartość bajtu.

Explicit(Half to BigInteger)

Jawnie konwertuje Half wartość na dużą liczbę całkowitą.

Explicit(Double to BigInteger)

Definiuje jawną konwersję DoubleBigInteger wartości na wartość.

Explicit(Decimal to BigInteger)

Definiuje jawną konwersję DecimalBigInteger obiektu na wartość.

Explicit(BigInteger to Int32)

Definiuje jawną konwersję BigInteger obiektu na wartość całkowitą z podpisem 32-bitowym.

Explicit(BigInteger to SByte)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Alternatywa zgodna ze specyfikacją CLS
System.Int16

Definiuje jawną konwersję BigInteger obiektu na podpisaną wartość 8-bitową.

Ten interfejs API nie jest zgodny ze specyfikacją CLS. Zgodna alternatywa to 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

Parametry

value
BigInteger

Wartość do konwersji na podpisaną wartość 8-bitową.

Zwraca

Obiekt zawierający wartość parametru value .

Atrybuty

Wyjątki

value wartość jest mniejsza niż SByte.MinValue lub jest większa niż SByte.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na SByte wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem SByte typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CSByte w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem SByte typu danych. Nie ma utraty dokładności w wartości wynikowej SByte , jeśli konwersja zakończy się pomyślnie.

Dotyczy

Explicit(Single to BigInteger)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję SingleBigInteger wartości na wartość.

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

Parametry

value
Single

Wartość, która ma być konwertowana na wartość BigInteger.

Zwraca

Obiekt zawierający wartość parametru value .

Wyjątki

Przykłady

Poniższy przykład konwertuje poszczególne elementy w tablicy Single wartości na BigInteger obiekty, a następnie wyświetla wynik każdej konwersji. Należy pamiętać, że każda część ułamkowa wartości jest obcięta Single podczas konwersji.

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

Uwagi

Każda część ułamkowa parametru value jest obcięta przed konwersją.

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Ponieważ konwersja z Single na BigInteger może obejmować obcinanie dowolnej części valueułamkowej kompilatorów języka nie wykonuje tej konwersji automatycznie. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

W przypadku języków, które nie obsługują operatorów niestandardowych, alternatywna metoda to BigInteger.BigInteger(Single).

Dotyczy

Explicit(Complex to BigInteger)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Jawnie konwertuje Complex wartość na dużą liczbę całkowitą.

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

Parametry

value
Complex

Wartość do konwersji.

Zwraca

value przekonwertowane na dużą liczbę całkowitą.

Dotyczy

Explicit(BigInteger to UIntPtr)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Jawnie konwertuje dużą liczbę całkowitą na UIntPtr wartość.

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

Parametry

value
BigInteger

Wartość do konwersji.

Zwraca

UIntPtr

unativeint

value przekonwertowane na UIntPtr wartość.

Atrybuty

Dotyczy

Explicit(BigInteger to UInt64)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Alternatywa zgodna ze specyfikacją CLS
System.Double

Definiuje jawną konwersję BigInteger obiektu na niepodpisaną wartość całkowitą 64-bitową.

Ten interfejs API nie jest zgodny ze specyfikacją CLS. Zgodna alternatywa to 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

Parametry

value
BigInteger

Wartość do konwersji na niepodpisaną liczbę całkowitą 64-bitową.

Zwraca

Obiekt zawierający wartość parametru value .

Atrybuty

Wyjątki

value wartość jest mniejsza niż UInt64.MinValue lub jest większa niż UInt64.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na UInt64 wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem UInt64 typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CULng w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem UInt64 typu danych. Nie ma utraty dokładności w wartości wynikowej UInt64 , jeśli konwersja zakończy się pomyślnie.

Dotyczy

Explicit(BigInteger to UInt32)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Alternatywa zgodna ze specyfikacją CLS
System.Int64

Definiuje jawną konwersję BigInteger obiektu na niepodpisaną wartość całkowitą 32-bitową.

Ten interfejs API nie jest zgodny ze specyfikacją CLS. Zgodna alternatywa to 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

Parametry

value
BigInteger

Wartość do konwersji na niepodpisaną liczbę całkowitą 32-bitową.

Zwraca

Obiekt zawierający wartość parametru value .

Atrybuty

Wyjątki

value wartość jest mniejsza niż UInt32.MinValue lub jest większa niż UInt32.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na UInt32 wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem UInt32 typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CUInt w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem UInt32 typu danych. Nie ma utraty dokładności w wartości wynikowej UInt32 , jeśli konwersja zakończy się pomyślnie.

Dotyczy

Explicit(BigInteger to UInt16)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Alternatywa zgodna ze specyfikacją CLS
System.Int32

Definiuje jawną konwersję BigInteger obiektu na niepodpisaną 16-bitową wartość całkowitą.

Ten interfejs API nie jest zgodny ze specyfikacją CLS. Zgodna alternatywa to 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

Parametry

value
BigInteger

Wartość do konwersji na niepodpisaną 16-bitową liczbę całkowitą.

Zwraca

Obiekt zawierający wartość parametru value .

Atrybuty

Wyjątki

value wartość jest mniejsza niż UInt16.MinValue lub jest większa niż UInt16.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na UInt16 wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem UInt16 typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CUShort w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem UInt16 typu danych. Nie ma utraty dokładności w wartości wynikowej UInt16 , jeśli konwersja zakończy się pomyślnie.

Dotyczy

Explicit(BigInteger to UInt128)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Jawnie konwertuje dużą liczbę całkowitą na UInt128 wartość.

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

Parametry

value
BigInteger

Wartość do konwersji.

Zwraca

value przekonwertowane na UInt128 wartość.

Atrybuty

Dotyczy

Explicit(BigInteger to Single)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję BigInteger obiektu na wartość zmiennoprzecinkową o pojedynczej precyzji.

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

Parametry

value
BigInteger

Wartość do konwersji na wartość zmiennoprzecinkową o pojedynczej precyzji.

Zwraca

Obiekt zawierający najbliższą możliwą reprezentację parametru value .

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na Single wartości.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych lub utratę dokładności. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CSng w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

BigInteger Ponieważ wartość może znajdować się poza zakresem Single typu danych, ta operacja jest konwersją zawężającą. Jeśli konwersja nie powiedzie się, nie zgłasza wartości OverflowException. Zamiast tego, jeśli BigInteger wartość jest mniejsza niż Single.MinValue, wynikowa Single wartość to Single.NegativeInfinity. BigInteger Jeśli wartość jest większa niż Single.MaxValue, wynikowa Single wartość to Single.PositiveInfinity.

Konwersja obiektu na element BigIntegerSingle może obejmować utratę dokładności. W niektórych przypadkach utrata dokładności może spowodować powodzenie operacji rzutowania lub konwersji, nawet jeśli BigInteger wartość znajduje się poza zakresem Single typu danych. Poniższy przykład stanowi ilustrację. Przypisuje maksymalną wartość do Single dwóch BigInteger zmiennych, zwiększa jedną BigInteger zmienną o 9,999e291 i testuje dwie zmienne pod kątem równości. Zgodnie z oczekiwaniami wywołanie BigInteger.Equals(BigInteger) metody pokazuje, że są one nierówne. Jednak konwersja większej BigInteger wartości z powrotem na Single powodzenie, chociaż BigInteger wartość teraz przekracza Single.MaxValuewartość .

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

Dotyczy

Explicit(BigInteger to IntPtr)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Jawnie konwertuje dużą liczbę całkowitą na IntPtr wartość.

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

Parametry

value
BigInteger

Wartość do konwersji.

Zwraca

IntPtr

nativeint

value przekonwertowane na IntPtr wartość.

Dotyczy

Explicit(BigInteger to Int64)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję BigInteger obiektu na 64-bitową wartość całkowitą ze znakiem.

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

Parametry

value
BigInteger

Wartość do konwersji na 64-bitową liczbę całkowitą ze znakiem.

Zwraca

Obiekt zawierający wartość parametru value .

Wyjątki

value wartość jest mniejsza niż Int64.MinValue lub jest większa niż Int64.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na Int64 wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem Int64 typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CLng w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem Int64 typu danych.

Dotyczy

Explicit(BigInteger to Int16)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję BigInteger obiektu na wartość całkowitą z podpisem 16-bitowym.

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

Parametry

value
BigInteger

Wartość do konwersji na 16-bitową liczbę całkowitą ze znakiem.

Zwraca

Obiekt zawierający wartość parametru value .

Wyjątki

value wartość jest mniejsza niż Int16.MinValue lub jest większa niż Int16.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na Int16 wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem Int16 typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CShort w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem Int16 typu danych. Nie ma utraty dokładności w wartości wynikowej Int16 , jeśli konwersja zakończy się pomyślnie.

Dotyczy

Explicit(BigInteger to Int128)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Jawnie konwertuje dużą liczbę całkowitą na Int128 wartość.

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

Parametry

value
BigInteger

Wartość do konwersji.

Zwraca

value przekonwertowane na Int128 wartość.

Dotyczy

Explicit(BigInteger to Half)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Jawnie konwertuje dużą liczbę całkowitą na Half wartość.

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

Parametry

value
BigInteger

Wartość do konwersji.

Zwraca

value przekonwertowane na Half wartość.

Dotyczy

Explicit(BigInteger to Double)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję BigIntegerDouble obiektu na wartość.

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

Parametry

value
BigInteger

Wartość, która ma być konwertowana na wartość Double.

Zwraca

Obiekt zawierający wartość parametru value .

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na Double wartości.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CDbl w Visual Basic).

BigInteger Ponieważ wartość może znajdować się poza zakresem Double typu danych, ta operacja jest konwersją zawężającą. Jeśli konwersja nie powiedzie się, nie zgłasza wartości OverflowException. Zamiast tego, jeśli BigInteger wartość jest mniejsza niż Double.MinValue, wynikowa Double wartość to Double.NegativeInfinity. BigInteger Jeśli wartość jest większa niż Double.MaxValue, wynikowa Double wartość to Double.PositiveInfinity.

Konwersja obiektu na element BigIntegerDouble może obejmować utratę dokładności. W niektórych przypadkach utrata dokładności może spowodować powodzenie operacji rzutowania lub konwersji, nawet jeśli BigInteger wartość znajduje się poza zakresem Double typu danych. Poniższy przykład stanowi ilustrację. Przypisuje maksymalną wartość do Double dwóch BigInteger zmiennych, zwiększa jedną BigInteger zmienną o 9,999e291 i testuje dwie zmienne pod kątem równości. Zgodnie z oczekiwaniami wywołanie BigInteger.Equals(BigInteger) metody pokazuje, że są one nierówne. Jednak konwersja większej BigInteger wartości z powrotem na Double powodzenie, chociaż BigInteger wartość teraz przekracza Double.MaxValuewartość .

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

Dotyczy

Explicit(BigInteger to Decimal)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję BigIntegerDecimal obiektu na wartość.

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

Parametry

value
BigInteger

Wartość, która ma być konwertowana na wartość Decimal.

Zwraca

Obiekt zawierający wartość parametru value .

Wyjątki

value wartość jest mniejsza niż decimal.MinValue lub większa niż decimal.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na Decimal wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem Decimal typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CDec w Visual Basic).

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem Decimal typu danych.

Dotyczy

Explicit(BigInteger to Char)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Jawnie konwertuje dużą liczbę całkowitą na Char wartość.

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

Parametry

value
BigInteger

Wartość do konwersji.

Zwraca

value przekonwertowane na Char wartość.

Dotyczy

Explicit(BigInteger to Byte)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję BigInteger obiektu na niepodpisaną wartość bajtu.

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

Parametry

value
BigInteger

Wartość, która ma być konwertowana na wartość Byte.

Zwraca

Obiekt zawierający wartość parametru value .

Wyjątki

value wartość jest mniejsza niż Byte.MinValue lub większa niż Byte.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na Byte wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem Byte typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CByte w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem Byte typu danych. Nie ma utraty dokładności w wartości wynikowej Byte , jeśli konwersja zakończy się pomyślnie.

Dotyczy

Explicit(Half to BigInteger)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Jawnie konwertuje Half wartość na dużą liczbę całkowitą.

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

Parametry

value
Half

Wartość do konwersji.

Zwraca

value przekonwertowane na dużą liczbę całkowitą.

Dotyczy

Explicit(Double to BigInteger)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję DoubleBigInteger wartości na wartość.

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

Parametry

value
Double

Wartość, która ma być konwertowana na wartość BigInteger.

Zwraca

Obiekt zawierający wartość parametru value .

Wyjątki

Przykłady

Poniższy przykład konwertuje poszczególne elementy w tablicy Double wartości na BigInteger obiekty, a następnie wyświetla wynik każdej konwersji. Należy pamiętać, że każda część ułamkowa wartości jest obcięta Double podczas konwersji.

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

Uwagi

Każda część ułamkowa parametru value jest obcięta przed konwersją.

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Ponieważ konwersja z Double na BigInteger może obejmować obcinanie dowolnej części valueułamkowej kompilatorów języka nie wykonuje tej konwersji automatycznie. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

W przypadku języków, które nie obsługują operatorów niestandardowych, alternatywna metoda to BigInteger.BigInteger(Double).

Dotyczy

Explicit(Decimal to BigInteger)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję DecimalBigInteger obiektu na wartość.

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

Parametry

value
Decimal

Wartość, która ma być konwertowana na wartość BigInteger.

Zwraca

Obiekt zawierający wartość parametru value .

Przykłady

Poniższy przykład konwertuje poszczególne elementy w tablicy Decimal wartości na BigInteger obiekty, a następnie wyświetla wynik każdej konwersji. Należy pamiętać, że każda część ułamkowa wartości jest obcięta Decimal podczas konwersji.

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

Uwagi

Każda część ułamkowa parametru value jest obcięta przed konwersją.

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Ponieważ konwersja z Decimal na BigInteger może obejmować obcinanie dowolnej części valueułamkowej kompilatorów języka nie wykonuje tej konwersji automatycznie. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

W przypadku języków, które nie obsługują operatorów niestandardowych, alternatywna metoda to BigInteger.BigInteger(Decimal).

Dotyczy

Explicit(BigInteger to Int32)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Definiuje jawną konwersję BigInteger obiektu na wartość całkowitą z podpisem 32-bitowym.

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

Parametry

value
BigInteger

Wartość do konwersji na 32-bitową liczbę całkowitą ze znakiem.

Zwraca

Obiekt zawierający wartość parametru value .

Wyjątki

value wartość jest mniejsza niż Int32.MinValue lub jest większa niż Int32.MaxValue.

Przykłady

Poniższy przykład ilustruje konwersję BigInteger na Int32 wartości. Obsługuje również zgłaszaną OverflowException wartość, ponieważ BigInteger wartość znajduje się poza zakresem Int32 typu danych.

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

Uwagi

Przeciążenia Explicit(Decimal to BigInteger) metody definiują typy, do których lub z których BigInteger można przekonwertować obiekt. Kompilatory języka nie wykonują tej konwersji automatycznie, ponieważ mogą one obejmować utratę danych. Zamiast tego wykonują konwersję tylko wtedy, gdy jest używany operator rzutowania (w języku C#) lub funkcja konwersji (np CType . lub CInt w Visual Basic). W przeciwnym razie wyświetlają błąd kompilatora.

Ponieważ ta operacja definiuje konwersję zawężającą, może zgłaszać OverflowException wartość w czasie wykonywania, jeśli BigInteger wartość znajduje się poza zakresem Int32 typu danych. Nie ma utraty dokładności w wartości wynikowej Int32 , jeśli konwersja zakończy się pomyślnie.

Dotyczy