Chapter 4: Summary

This chapter began by introducing the C# operators related to assignment and arithmetic. Next, we used the operators along with the const keyword to declare constants. Coverage of all the C# operators was not sequential, however. Before discussing the relational and logical comparison operators, the chapter introduced the if statement and the important concepts of code blocks and scope. To close out the coverage of operators, we discussed the bitwise operators, especially regarding masks. We also discussed other control flow statements such as loops, switch, and goto, and ended the chapter with a discussion of the C# preprocessor directives.

Operator precedence was discussed earlier in the chapter; Table 4.7 summarizes the order of precedence across all operators, including several that have not yet been covered.

Table 4.7: Operator Order of Precedence*




x.y f(x) a[x] x++ x-- new

typeof(T) checked(x) unchecked(x) default(T)

nameof(x) delegate{} ()


+ - ! ~ ++x --x (T)x await x


* / %


+ -


<< >>

Relational and type testing

< > <= >= is as


== !=

Logical AND


Logical XOR


Logical OR


Conditional AND


Conditional OR






Assignment and lambda

= *= /= %= += -= <<= >>= &= ^= |= =>

* Rows appear in order of precedence from highest to lowest.

Perhaps one of the best ways to review all of the content covered in Chapters 1, 2, and 3 is to look at the tic-tac-toe program found in Chapter04\TicTacToe.cs. By reviewing this program, you can see one way in which you can combine all that you have learned into a complete program.

{{ snackbarMessage }}