Editorconfig Guide.e

Prefer foreach explicit cast in source

EditorConfig key: dotnet-style-prefer-foreach-explicit-cast-in-source

Prefer foreach explicit cast in source

dotnet-style-prefer-foreach-explicit-cast-in-source

This option controls when a foreach loop's implicit cast should be made explicit at the call site.

Default value:

when_strongly_typed

Possible values:

  • always
  • when_strongly_typed

Examples

always
var list = new List<object>();
foreach (string item in list) { }
when_strongly_typed
var list = new List<object>();
foreach (string item in list.Cast<string>()) { }