Compartir a través de


Complex Explicit Conversion (Decimal to Complex)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

Syntax

'Declaration
Public Shared Narrowing Operator CType ( _
    value As Decimal _
) As Complex
public static explicit operator Complex (
    decimal value
)

Parameters

  • value
    Type: System.Decimal
    The value to convert to a complex number.

Return Value

Type: System.Numerics.Complex
A complex number that has a real component equal to value and an imaginary component equal to zero.

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.

Examples

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

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)
   outputBlock.Text += String.Format("{0,30}  -->  {1}", number, c1) & vbCrLf
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)
decimal[] numbers = { Decimal.MinValue, -18.35m, 0m, 1893.019m, 
                      Decimal.MaxValue };
foreach (decimal number in numbers)
{
   System.Numerics.Complex c1 = (System.Numerics.Complex)number;
   outputBlock.Text += String.Format("{0,30}  -->  {1}", number, c1) + "\n";
}
// 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)

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.