Complex.Explicit 运算符

定义

定义 Complex 对象与其他类型之间的显式转换。

重载

Explicit(UInt128 to Complex)

将值显式转换为 UInt128 双精度复数。

Explicit(BigInteger to Complex)

定义从 BigInteger 值到复数的显式转换。

Explicit(Decimal to Complex)

定义从 Decimal 值到复数的显式转换。

Explicit(Int128 to Complex)

将值显式转换为 Int128 双精度复数。

Explicit(UInt128 to Complex)

Source:
Complex.cs
Source:
Complex.cs
Source:
Complex.cs

重要

此 API 不符合 CLS。

将值显式转换为 UInt128 双精度复数。

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

参数

value
UInt128

要转换的值。

返回

value 转换为双精度复数。

属性

适用于

Explicit(BigInteger to Complex)

Source:
Complex.cs
Source:
Complex.cs
Source:
Complex.cs

定义从 BigInteger 值到复数的显式转换。

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

参数

value
BigInteger

要转换为复数的值。

返回

一个复数,其实部等于 value,虚部等于零。

示例

下面的示例演示了值到Complex值的显式转换BigInteger

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)

注解

显式转换运算符定义可转换为 Complex 对象的类型。 语言编译器不会自动执行此转换,因为它可能涉及数据丢失。 相反,仅当转换运算符在 C#) 中 (或使用转换函数 ((如 CType 在 Visual Basic) 中)时,它们才会执行转换。 否则,它们会显示编译器错误。

将值转换为 BigInteger 复数的实部可能会导致精度损失,因为 Double是复数 Real 属性的类型,其有效位数比 BigInteger少。

如果由于 BigInteger 值不在类型的范围内 Double 而导致转换失败,则操作不会引发 OverflowException。 相反,如果 value 小于 MinValue,则结果是属性值等于 NegativeInfinityReal复数。 如果 value 大于 MaxValue,则结果为属性值等于 PositiveInfinityReal复数。

适用于

Explicit(Decimal to Complex)

Source:
Complex.cs
Source:
Complex.cs
Source:
Complex.cs

定义从 Decimal 值到复数的显式转换。

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

参数

value
Decimal

要转换为复数的值。

返回

一个复数,其实部等于 value,虚部等于零。

示例

下面的示例演示了值到Complex值的显式转换Decimal

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)

注解

显式转换运算符定义可转换为 Complex 对象的类型。 语言编译器不会自动执行此转换,因为它可能涉及数据丢失。 相反,仅当转换运算符在 C#) 中 (或使用转换函数 ((如 CType 在 Visual Basic) 中)时,它们才会执行转换。 否则,它们会显示编译器错误。

将值转换为 Decimal 复数的实部可能会导致精度损失,因为 Double是复数 Real 属性的类型,其有效位数比 Decimal少。

适用于

Explicit(Int128 to Complex)

Source:
Complex.cs
Source:
Complex.cs
Source:
Complex.cs

将值显式转换为 Int128 双精度复数。

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

参数

value
Int128

要转换的值。

返回

value 转换为双精度复数。

适用于