JetBrains Rider 2019.3 Help

Code Inspection: Redundant comma in switch expression

Switch expressions introduced in C# 8.0 allow adding a trailing comma after the last switch item.

Currently, JetBrains Rider suggests removing optional trailing commas for the sake of conciseness, and this behavior is not configurable. We are going to introduce a configurable code syntax style for trailing commas in the coming versions — here is the tracking issue.

If you prefer having trailing commas in switch expressions, just disable this inspection: press Alt+Enter and choose Inspection: "Redundant comma in switch expression" | Configure inspection severity | Do not show.

enum MyColor { Red, Green, Blue } string GetColor(MyColor color) => color switch { MyColor.Red => "Red", MyColor.Green => "Green", MyColor.Blue => "Blue", // trailing comma after the last expression is optional _ => "Unknown", };
Last modified: 13 February 2020