语言

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
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
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 零,虚部等于零。

示例

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

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)
    let numbers =
        [ (bigint Double.MaxValue) * 2I
          BigInteger.Parse "901345277852317852466891423"
          BigInteger.One ]

    for number in numbers do
        let c1 = Complex(float number, 0.)
        printfn $"{number, 30}  -->  {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属性的类型,其有效位数比 a BigInteger少。

如果转换失败,因为BigInteger值不在类型范围内Double,则操作不会引发 。OverflowException 相反,如果value小于MinValue,则结果是一个属性值等于Real的复数NegativeInfinity。 如果value大于MaxValue,则结果是一个属性值等于Real的复数PositiveInfinity。

适用于

Explicit(Decimal to Complex)

Source:
Complex.cs
Source:
Complex.cs
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 零,虚部等于零。

示例

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

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)
    let numbers = [ Decimal.MinValue; -18.35m; 0m; 1893.019m; Decimal.MaxValue ]

    for number in numbers do
        let c1 = Complex(float number, 0.)
        printfn $"{number, 30}  -->  {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属性的类型,其有效位数比 a Decimal少。

适用于

Explicit(Int128 to Complex)

Source:
Complex.cs
Source:
Complex.cs
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 转换为双精度复数。

适用于