Changes

C Sharp Operators and Expressions

972 bytes added, 20:24, 14 January 2008
Comparison Operators
== Comparison Operators ==
 
In addition to mathematical and assignment operators, C# also includes set of logical operators useful for performing comparisons. These operators all return a Boolean (bool) ''true'' or ''false'' result depending on the result of the comparison. These operators are ''binary'' in that they work with two operands.
 
Comparison operators are most frequently used in constructing program flow control. For example an ''if'' statement may be constructed based on whether one value matches another:
 
<pre>
if (x == y)
System.Console.WriteLine ("x is equal to y");
</pre>
 
The resullt of a comparisom may also be stored in a ''bool'' variable. For example, the following code will result a ''true'' value being stored in the variable result:
 
<pre>
bool result;
int x = 10;
int y = 20;
 
result = x < y;
</pre>
 
Clearly 10 is less than 20, resulting in a ''true'' evaluation of the ''x < y'' expression. The following table lists the full set of C# comparison operators: