Complex.Inequality(Complex, Complex) 运算符


返回一个值,该值指示两个复数是否不相等。Returns a value that indicates whether two complex numbers are not equal.

 static bool operator !=(System::Numerics::Complex left, System::Numerics::Complex right);
public static bool operator != (System.Numerics.Complex left, System.Numerics.Complex right);
static member op_Inequality : System.Numerics.Complex * System.Numerics.Complex -> bool
Public Shared Operator != (left As Complex, right As Complex) As Boolean



要比较的第一个值。The first value to compare.


要比较的第二个值。The second value to compare.


如果 trueleft 不相等,则为 right;否则为 falsetrue if left and right are not equal; otherwise, false.


Equality 方法为复数定义不相等运算符的运算。The Equality method defines the operation of the inequality operator for complex numbers. 它可以实现如下所示的代码:It enables code such as the following:

Complex c1 = new Complex(12.6, 4.3);
Complex c2 = new Complex(11.1, 8.9);
if (c1 != c2) 
Dim c1 As New Complex(12.6, 4.3)
Dim c2 As New Complex(11.1, 8.9)
If c1 <> c2 Then 

不支持自定义运算符的语言可以通过调用 Equals(Complex) 方法并反转其值来测试是否不相等。Languages that do not support custom operators can test for inequality by calling the Equals(Complex) method and reversing its value.

请注意,由于精度差异,两个明显等效的复数可以视为不相等。Note that, because of differences in precision, two complex numbers that are apparently equivalent can be considered unequal. 一种可能的解决方法是实现一个比较方法,该方法仅在复数的两个实部和虚部的差超过特定的阈值时才返回 true (例如,其中一个复数的实部或虚部的值的 .01%)。One possible workaround is to implement a comparison method that returns true only if the difference between the two real and imaginary parts of the complex numbers exceeds a certain threshold (such as .01% of the value of the real or imaginary component of one of the complex numbers). 有关更多信息,请参见 Equals(Complex) 方法。For more information, see the Equals(Complex) method.