Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 1.36 KB

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

File metadata and controls

35 lines (25 loc) · 1.36 KB
title description ms.date ms.topic author ms.author manager ms.subservice dev_langs
Convert switch statement to switch expression
Learn how to use the Quick Actions and Refactorings menu to convert a switch statement to a C# 8.0 switch expression.
06/19/2019
reference
mikadumont
midumont
mijacobs
general-ide
CSharp

Convert switch statement to switch expression

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

  1. In your project file, set the language version to preview since switch expressions are a new C# 8.0 feature.

  2. Place your cursor in the switch keyword and press Ctrl+. to trigger the Quick Actions and Refactorings menu.

  3. Select Convert switch statement to expression.

    Convert switch statement to switch expression

See also