Jump to content

Conditional Cases in Switch Statements: Revision history

Diff selection: Mark the radio buttons of the revisions to compare and hit enter or the button at the bottom.
Legend: (cur) = difference with latest revision, (prev) = difference with preceding revision, m = minor edit.

17 January 2025

  • curprev 16:5016:50, 17 January 2025 Chr1ss talk contribs 774 bytes +774 Created page with "When working with switch statements, you can use a when clause instead of an if/else in your case expressions. The switch statement with pattern matching was introduced in C# 7. <pre> switch( cow.Name ) { case "Alf": if( cow.Weight >= 100 ) { // Do This } else { // Do that } break; default: // Else break; } </pre> <pre> switch ( cow.Name ) { case "Alf" when cow...."