ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Code Syntax Style: Trailing Commas

Last modified: 21 July 2022

When multiple items are separated by the comma (object, array, and collection initializers, as well as enums and switch expressions) , C# allows you to have the trailing comma after the last item.

Some developers consider the trailing comma redundant, but it has a number of benefits, especially in multi-line declarations:

  • It is easier to add or remove the last item, because it is always another single line. You can also press Ctrl+D to duplicate the last line.

  • Your version control diffs are cleaner when you add a new item in the end of the list.

  • It is easier to create code generators for initializers.

ReSharper helps you arrange trailing commas in the existing code and takes your preferences into account when it produces new code with code completion and code generation features, applies code templates and performs refactorings.