ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Use collection expression syntax

Last modified: 14 November 2024

Collection expressions introduced in C#12 provide a more concise syntax for collection initializations. Therefore, ReSharper suggests using this syntax instead of the legacy collection initializer syntax:

If the collection initializer is immediately followed by Add() calls on the collection, the quick-fix will also integrate these calls into the collection expression: