O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Logical Operators

So far, our Boolean expressions have consisted of only simple conditions, such as balance <= 20000 in line 13 of Listing 8.4 or (choice == "A") in line 11 of Listing 8.5, with only one comparison operator. However, it is often beneficial to combine several simple conditions (sub-Boolean expressions) into one larger Boolean expression. Logical operators allow us to do exactly that.

C# contains three logical operators that are semantically equivalent to “and,” “or,” and “not” in our everyday language. The latter are used in Figure 8.12 as a general introduction to C#'s equivalents. Notice that each phrase could be part of a normal conversation, and that we intuitively understand their meaning.

Figure 8.12. Three logical “operators” ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required