Comparison Operators and Boolean Expressions

You have already seen a few of the comparison operators in action. This section presents the six fundamental comparison operators found in C# and explains how they form Boolean expressions.

A comparison operator allows two data values to be compared and generates a result of type bool. If the comparison is true, it produces the bool value true, and it produces the value false if the comparison is untrue.

The six comparison operators, can be divided into two categories—relational and equality. They are all listed in Table 8.1.

Table 8.1. The Six Fundamental Comparison Operators
Math Notation C# Syntax Name Example Category Explanation
> > Greater-than x > y Relational Returns true if x is greater than ...

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.