You're not doing anything with the values returned from
FilterWithYield
so it's optimized out.
Change
FilterWithYield();
foreach (int i in MyList)
{
Console.WriteLine(i);
}
to
foreach (int i in FilterWithYield())
{
Console.WriteLine(i);
}
And you should see the method being hit.
Hope this helps,
Fredrik