Convert if statement to switch statement or switch expression
This refactoring applies to:
- C#
What: Convert an if statement to a switch statement or to the C# 8.0 switch expression.
When: You want to convert an if
statement to a switch
statement or a switch
expression and vice versa.
Why: If you are using an if
statement, this refactoring enables an easy transition to switch
statements or switch
expressions.
How-to
Place your cursor in the
if
keyword.Press Ctrl+. to trigger the Quick Actions and Refactorings menu.
Select from the following two options:
Select Convert to 'switch' statement.
Select Convert to 'switch' expression.
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for