3 C# Operators & Conditionals

 

This chapter covers

  • Using operators and expressions in C#
  • Correctly controlling Operator associativity and precedence
  • Working with Conditional Selection statements in C#
  • Developing a Rock-Paper-Scissor minigame

In the previous chapters, we already set up two projects. We learned about variables, data types, and the random class. We also learned about concatenation and how we can get custom results using more exciting features like conditional statements and loops. These previous chapters were somewhat limited for theory and had to up the complexity by adding yet potentially unfamiliar statements. However, this chapter will achieve the necessary theoretical complexity to develop a proper project. This is mainly because we will finally deep dive into conditional statements in C#, covering statements such as the switch statement and the ternary operator. Also, everything commonly missed about operators, operator evaluation, operator precedence, and, additionally, learning about nullable and what constant variables have that switch statements want, among others.

3.1 What are Operators and Expressions

 
 

3.2 Types of Operators

 
 
 

3.3 Operator priority

 

3.3.1 Operator precedence

 
 

3.3.2 Operator associativity

 
 

3.3.3 Operand evaluation

 
 

3.4 Conditional statements

 
 
 
 

3.4.1 The if statement

 
 

3.4.2 The ternary operator ?:

 

3.4.3 The switch statement

 
 
 
 

3.5 Rock Paper Scissor

 
 

3.5.1 The project

 
 

3.5.2 Our Code

 
 
 

3.6 Source

 

3.7 Summary

 
 
 

3.8 References

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest