Skip to content

Commit cb71a29

Browse files
author
Ruben Schmidmeister
authored
Merge pull request #27 from messerli-informatik-ag/switch-expression
Recommend switch expressions
2 parents 6b8fbc8 + 76a8139 commit cb71a29

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

documentation/src/basic-constructs.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,21 @@ return condition
6565
```
6666
*ternary operator*
6767

68-
## Expression-bodied members
68+
## Switch Expression
69+
70+
Prefer switch expressions over switch statements.
71+
72+
```csharp
73+
return animalKind switch
74+
{
75+
AnimalKind.Dog => "dog",
76+
AnimalKind.Cat => "cat",
77+
_ => throw new InvalidOperationException($"Unsupported animal kind {animalKind}"),
78+
};
79+
```
80+
*switch expression*
81+
82+
## Expression-bodied Members
6983

7084
Use the expression body syntax when a member returns a single expression.
7185
Move the arrow to the next line when the expression gets too long.

0 commit comments

Comments
 (0)