IDE0028 raised when initializing a collection from another collection. #75981
Labels
Area-Compilers
Bug
Code Gen Quality
Room for improvement in the quality of the compiler's generated code
New Feature - Collection Expressions
Milestone
Version Used:
Dotnet 9.0.
Steps to Reproduce:
A minimal repro, with source-code provided, is ideal. Most compiler/language issues can be distilled into a snippet that can be pasted into sharplab.
Diagnostic Id:
IDE0028: Collection initialization can be simplified
Expected Behavior:
No diagnostic.
Actual Behavior:
IDE0028 is raised and suggests changing syntax to
[.. strings]
. This syntax is effectively:This is less efficient since it will initialize the collection with default capacity and then grow / copy as Adds are made. Collection constructors should be preferred in most cases since they can more-efficiently initialize the internal collection than calling Add N times.
The text was updated successfully, but these errors were encountered: