Comparison Operators
Above, we used the > operator to mean “greater than.” Most of these operators are the same in C# as they are in C and other languages. In Table 2-5, note particularly that “is equal to” requires two equal signs and that “not equal” is different than in FORTRAN or VB.
>
|
greater than
|
<
|
less than
|
==
|
is equal to
|
!=
|
is not equal to
|
>=
|
greater than or equal to
|
<=
|
less than or equal to
|
Table 1: Comparison Operators in C#
Combining Conditions
When you need to combine two or more conditions in a single if or other logical statement, you use the symbols for the logical and, or, and not operators. These are totally different than any other languages except C/C++ and are confusingly like the bitwise operators shown in Table 2.
&&
|
logical And
|
||
|
logical Or
|
~
|
logical Not
|
Table 2 Boolean operators in C#
No comments:
Post a Comment