Complex.Explicit Operator

Definition

Defines an explicit conversion between a Complex object and another type.

Overloads

Explicit(Decimal to Complex)

Defines an explicit conversion of a Decimal value to a complex number.

Explicit(BigInteger to Complex)

Defines an explicit conversion of a BigInteger value to a complex number.

Explicit(Decimal to Complex)

Defines an explicit conversion of a Decimal value to a complex number.

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

Parameters

value
Decimal

The value to convert to a complex number.

Returns

A complex number that has a real component equal to value and an imaginary component equal to zero.

Examples

The following example illustrates the explicit conversion of Decimal values to Complex values.

decimal[] numbers = { Decimal.MinValue, -18.35m, 0m, 1893.019m, 
                      Decimal.MaxValue };
foreach (decimal number in numbers)
{
   System.Numerics.Complex c1 = (System.Numerics.Complex) number;
   Console.WriteLine("{0,30}  -->  {1}", number, c1);
}   
// The example displays the following output:
//    -79228162514264337593543950335  -->  (-7.92281625142643E+28, 0)
//                            -18.35  -->  (-18.35, 0)
//                                 0  -->  (0, 0)
//                          1893.019  -->  (1893.019, 0)
//     79228162514264337593543950335  -->  (7.92281625142643E+28, 0)
Dim numbers() As Decimal = { Decimal.MinValue, -18.35d, 0d, 1893.019d, 
                             Decimal.MaxValue }
For Each number In numbers
   Dim c1 As System.Numerics.Complex = CType(number, 
                                             System.Numerics.Complex)
   Console.WriteLine("{0,30}  -->  {1}", number, c1)
Next   
' The example displays the following output:
'    -79228162514264337593543950335  -->  (-7.92281625142643E+28, 0)
'                            -18.35  -->  (-18.3500003814697, 0)
'                                 0  -->  (0, 0)
'                          1893.019  -->  (1893.01904296875, 0)
'     79228162514264337593543950335  -->  (7.92281625142643E+28, 0)

Remarks

Explicit conversion operators define types that can be converted to a Complex object. Language compilers do not perform this conversion automatically because it can involve data loss. Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as CType in Visual Basic) is used. Otherwise, they display a compiler error.

The conversion of a Decimal value to the real part of a complex number can result in a loss of precision because a Double, which is the type of the complex number's Real property, has fewer significant digits than a Decimal.

Explicit(BigInteger to Complex)

Defines an explicit conversion of a BigInteger value to a complex number.

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

Parameters

value
BigInteger

The value to convert to a complex number.

Returns

A complex number that has a real component equal to value and an imaginary component equal to zero.

Examples

The following example illustrates the explicit conversion of BigInteger values to Complex values.

BigInteger[] numbers= {
                 ((BigInteger) Double.MaxValue) * 2, 
                 BigInteger.Parse("901345277852317852466891423"), 
                 BigInteger.One }; 
foreach (BigInteger number in numbers)
{
  Complex c1 = (Complex) number;
   Console.WriteLine(c1);
}        
// The example displays the following output:
//       (Infinity, 0)
//       (9.01345277852318E+26, 0)
//       (1, 0)      
Dim numbers() As BigInteger = {
                 CType(Double.MaxValue, BigInteger) * 2, 
                 BigInteger.Parse("901345277852317852466891423"), 
                 BigInteger.One } 
For Each number In numbers
  Dim c1 As System.Numerics.Complex = CType(number, 
                                    System.Numerics.Complex)
   Console.WriteLine(c1)
Next        
' The example displays the following output:
'       (Infinity, 0)
'       (9.01345277852318E+26, 0)
'       (1, 0)      

Remarks

Explicit conversion operators define types that can be converted to a Complex object. Language compilers do not perform this conversion automatically because it can involve data loss. Instead, they perform the conversion only if a casting operator (in C#) or a conversion function (such as CType in Visual Basic) is used. Otherwise, they display a compiler error.

The conversion of a BigInteger value to the real part of a complex number can result in a loss of precision because a Double, which is the type of the complex number's Real property, has fewer significant digits than a BigInteger.

If the conversion is unsuccessful because the BigInteger value is out of the range of the Double type, the operation does not throw an OverflowException. Instead, if value is less than MinValue, the result is a complex number that has a Real property value equal to NegativeInfinity. If value is greater than MaxValue, the result is a complex number that has a Real property value equal to PositiveInfinity.

Applies to