Skip to content

"Convert to for" code fix produces invalid cast using "var" #50469

@bartdesmet

Description

@bartdesmet
var items = new[] { new { x = 1 } };

foreach (var item in items)
{
}

Attempting to apply the "Convert to for" code fix results in:

var items = new[] { new { x = 1 } };

for (int i = 0; i < items.Length; i++)
{
    var item = (var)items[i];
}

where the (var) cast is invalid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions