Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This refactoring applies to:
- C#
What: Convert a switch statement to a C# 8.0 switch expression.
When: You want to convert a switch
statement to a switch
expression and vice versa.
Why: If you are only using expressions, this refactoring enables an easy transition from traditional switch
statements.
How-to
In your project file, set the language version to preview since
switch
expressions are a new C# 8.0 feature.Place your cursor in the
switch
keyword and press Ctrl+. to trigger the Quick Actions and Refactorings menu.Select Convert switch statement to expression.