You can debug the method. The problem is, the code that you are trying to reach is never executed.
IEnumerable
methods with yield return
produce code that makes your sequence lazily, as you go through enumeration. However, when you do this
var sn = FilterWithYield();
you prepare to enumerate the sequence, but you do not start enumerating it.
If, on the other hand, you add a foreach
loop or call ToList()
on the result, your breakpoint would get hit:
foreach (var n in FilterWithYield()) {
Console.WriteLine(n);
}
or
var sn = FilterWithYield().ToList();