All rules
IDE0300Language rules (expression-level preferences)

Use collection expression for array

Use collection expression for array

Microsoft docs

Description

This rule flags places where a collection expression could be used to initialize an array. For example, this rule offers to simplify code like new C[] { ... }, new[] { ... }, and C[] c = { ... } into the collection expression form ([...]).

Example

// Code with violations.
int[] i = new int[] { 1, 2, 3 };
IEnumerable<int> j = new int[] { 1, 2, 3 };

// Fixed code.
int[] i = [1, 2, 3];
IEnumerable<int> j = [1, 2, 3];
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0