Permalink
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (29 sloc) 803 Bytes

Replace foreach with enumerator

Property Value
Id RR0206
Title Replace foreach with enumerator
Syntax foreach statement
Span foreach keyword
Enabled by Default

Usage

Before

foreach (var item in items)
{
    yield return item;
}

After

using (var en = items.GetEnumerator())
{
    while (en.MoveNext())
    {
        yield return item;
    }
}

See Also

(Generated with DotMarkdown)