Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1.41 KB

convert-if-statement-to-switch-statement-or-switch-expression.md

File metadata and controls

41 lines (28 loc) · 1.41 KB
title description ms.date ms.topic author ms.author manager ms.subservice dev_langs
Convert if statement to switch statement or expression
Learn how to use the Quick Actions and Refactorings menu to convert an if statement into a switch statement or a C# 8.0 switch expression.
03/10/2020
reference
mikadumont
midumont
mijacobs
general-ide
CSharp

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

  1. Place your cursor in the if keyword.

  2. Press Ctrl+. to trigger the Quick Actions and Refactorings menu.

  3. Select from the following two options:

    Select Convert to 'switch' statement.

    Convert if statement to switch statement

    Select Convert to 'switch' expression.

    Convert if statement to switch expression

See also