C# Tutorial: Control Flow
if/else, switch expressions, ternary operator, and short-circuit evaluation.
Directing execution
C# control flow is C-style but modern C# has added switch expressions that make code much more concise.
What you'll learn in this C# control flow tutorial
This interactive C# tutorial has 8 hands-on exercises. Estimated time: 15 minutes.
- if and else — Standard if/else — no surprises.
- else if chains — Chain multiple conditions.
- Ternary operator — The ternary `? :` is a compact if/else expression:
- switch statement — Match a single value against multiple cases.
- switch expression (modern C#) — C# 8+ switch expression is terser and returns a value.
- Logical operators — &&, ||, ! are short-circuit evaluated — right side is not evaluated if left side determines the result.
- Null conditional and coalescing — C# has operators for null safety:
- Pattern matching in if — C# 7+ `is` patterns match types and bind variables.
C# Control Flow concepts covered
- Directing execution