Comparing Equalities

Comparing values, particularly variables, is even more common than performing arithmetic (but you need to know how C# arithmetic works before you can understand the evaluation of equalities).

Comparison operators are most often used in decision-making structures, as explained in the next hour. Indeed, these operators are best understood using a simple if decision structure. In an if construct, C# considers the expression on the if statement, and if the expression equates to true, the code statement(s) are executed. For example, the following is an if operation (a silly one at that) expressed in English, not in C# code:

IF DOGS BARK, THEN SMILE.

If this were in C# code format, C# would evaluate the if condition, which in this ...

Get Sams Teach Yourself C#™ in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.