foreach vs ForEach using yield

Viewed 994

Is it possible to use yield inline at the ForEach method?

private static IEnumerable<string> DoStuff(string Input)
{
    List<string> sResult = GetData(Input);
    sResult.ForEach(x => DoStuff(x));

    //does not work
    sResult.ForEach(item => yield return item;); 

    //does work
    foreach(string item in sResult) yield return item;
}

if not, is there a reason why it doesn't work?

2 Answers
Related