This repository demonstrates the difference between traditional switch statements and modern switch expressions introduced in C# 8.
The goal is to show how modern C# encourages writing clearer, more expressive decision logic, rather than just reducing lines of code.
Switch expressions were introduced back in C# 8, yet many codebases still rely heavily on verbose switch statements.
With C# evolving rapidly (weβre already discussing C# 14), itβs important to not just learn new features β but to adopt better ways of expressing intent.
Switch expressions donβt just reduce lines of code β they improve how we think about decision logic.
- Traditional switch statements
- Modern switch expressions
- Same business logic implemented both ways
- Clear comparison focused on readability and intent
-
β Switch expressions
When your logic returns a value and can be expressed declaratively. -
β Switch statements
When your logic performs multiple actions or side effects.
- .NET SDK
- C# 8 or later
This repository is intentionally simple and educational.
Itβs meant for:
- Developers learning modern C#
- Code reviews & clean code discussions
- Sharing knowledge within the developer community
Feel free to fork, explore, or suggest improvements.
- Pattern matching
- Expression-based programming
- Clean code in C#
- Modern C# evolution