All rules
IDE0305Language rules (expression-level preferences)
Use collection expression for fluent
Use collection expression for fluent
Microsoft docsDescription
This rule flags places where a collection is built in a *fluent* manner, that is, where methods like Add(), AddRange(), AsSpan(), ToList(), and ToArray() are chained. Instead, a collection expression could be used to initialize the collection. For example, x.AddRange(y).Add(z).AsSpan() is converted to [x, ..y, z].
Example
// Code with violation.
List<int> i = new[] { 1, 2, 3 }.ToList();
IEnumerable<int> j = new[] { 1, 2, 3 }.ToList();
// Fixed code.
List<int> i = [1, 2, 3];
IEnumerable<int> j = [1, 2, 3];Your vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0