Skip to content

IDE0028 breaks working code #47632

@bart-degreed

Description

@bart-degreed

Version Used:
Visual Studio 2019 v16.7.2

Steps to Reproduce:

List<string> source = new List<string> {"A", "B", "C"};

List<string> items = new List<string>(source);
//                   ^^^ IDE0028: Collection can be simplified
items[^1] = "X";

Applying the suggested fix results in the next broken code:

List<string> items = new List<string>(source)
{
    [^1] = "X" // CS1913: Member '[^1]' cannot be initialized. It is not a field or property.
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions