ReSharper 2026.1 Help

Code inspection: Foreach loop can be converted into LINQ-expression but another 'GetEnumerator' method will be used

This inspection reports a yield return over another sequence that can be rewritten as a foreach. The fix replaces a query-style yield with an explicit foreach that enumerates the source and yields each element.

Example

public IEnumerable<int> GetSequence() { var ints = new int[10]; yield return ints; }
public IEnumerable<int> GetSequence() { var ints = new int[10]; foreach (var i in ints) yield return i; }

Quick-fix

Convert the sequence-producing statement into an explicit foreach loop.

30 March 2026