The comparison operators defined in C # are:
= = equals
!= is not equal to
< less than
> Greater than
<= less than or equal to
>= is greater than or equal to
integers and real numbers
These six comparison operators can be applied to both integer and real types. According to the IEEE 754 standard, comparison operators conform to the following rules:
If there is an operand of Nan (empty) then all the operators except "!=" result in false, and "!=" evaluates to "true". The "x!=y" part of any two operands is equivalent to "! (x==y) ". However, when one or two operands are Nan (empty), the results of the "<,>,<=," and ">=" operators are different from the logic of their opposite operators. For example, if X or Y is Nan, then x<y is always false, but! (x==y) is true.
When two operands are not Nan, the operators are based on the following order:
-∞<-max<...<-min<-0.0==+0.0<+min<...<+max<+∞
(where Min and Max are the smallest and largest finite values that the floating-point format can represent).
Note: in C #:
Positive zero and minus 0 are considered equal.
Negative infinity is considered to be less than any other value and is equal to another negative infinity.
Positive infinity is considered to be greater than any other value, just equal to another positive infinity.
Boolean type
There are actually only two kinds of comparison operators for Boolean types:
BOOL operator== (bool X,bool y);
BOOL Operator!= (bool X,bool y);
If both X and Y are true or false, the result of "= =" is true, or false.
Conversely, if both X and Y are true or false, the result of "!=" is false, otherwise the result is true. When the operand is of type bool, the "!=" operator and the ^ operator have equal results.
Enum type
Each of the enumerated types implicitly provides the following comparison operator.
BOOL operator== (E x,e y);
BOOL Operator!= (E x,e y);
BOOL operator< (E x,e y);
BOOL Operator> (E x,e y);
BOOL Operator<= (E x,e y);
BOOL Operator>= (E x,e y);
The result of executing "x op y", here x and Y are an enumeration type E, whose base class is U, and op represents the comparison operator, which is equivalent to ((U) x) op ((u) y), that is, the enumeration type comparison operator simply compares the base type values of the two operands.
Reference type
The predefined reference type equivalence operators are:
BOOL operator== (object X,object y);
BOOL Operator!= (object X,object y);
This operator returns the result of whether two reference types are equivalent.
String
The predefined string equivalence operators are:
BOOL operator== (string x,string y);
BOOL Operator!= (string x,string y);
Two string values are considered equal if one of the following conditions is true:
Two string values are null;
Two strings are non-null strings with the same string length and corresponding sequence of characters.
Note: The string equivalence operator compares the values of two strings, not the string references. When two separate string instances contain the same sequence of strings, the values of the two strings are considered equal. The reference type equivalence operator can be used to compare two string references, not to compare the values of two strings.
Representative type
Each representative type implicitly provides the following predefined comparison operators:
BOOL operator== (System.Delegate x,d y);
BOOL operator== (D x,system.delegate y);
BOOL Operator!= (System.Delegate x,d y);
BOOL Operator!= (D x,system.delegate y);