Since, as you can see here , the lambda function is compiled according to a separate method:
It:
x => DoStuff(x)
converted to
internal void <DoStuff>b__1_0(string x) { C.DoStuff(x); }
This separate method is not IEnumerable<> , so it obviously cannot support the yield keyword.
So for example:
item => yield return item;
will be converted to:
internal void <DoStuff>b__1_0(string item) { yield return item; }
which has yield but not IEnumerable<string> .
source share