Skip to content

lokeshvenkat17/modern-csharp-switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

modern-csharp-switch

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.


πŸ“Œ Why this repository?

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.


πŸ” What’s covered

  • Traditional switch statements
  • Modern switch expressions
  • Same business logic implemented both ways
  • Clear comparison focused on readability and intent

🧠 When to use what?

  • βœ… Switch expressions
    When your logic returns a value and can be expressed declaratively.

  • βœ… Switch statements
    When your logic performs multiple actions or side effects.


πŸ› οΈ Requirements

  • .NET SDK
  • C# 8 or later

πŸ“š Purpose

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

🀝 Contributions

Feel free to fork, explore, or suggest improvements.


πŸ”— Related topics

  • Pattern matching
  • Expression-based programming
  • Clean code in C#
  • Modern C# evolution

About

A simple comparison of switch statements and switch expressions in modern C# (C# 8+), highlighting cleaner and more expressive decision logic.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages