I thought I know everything about IEnumerable
but I just met a case that I cannot explain. When we call .Where linq method on a IEnumerable
Like many LINQ operations, Select is lazy and use deferred execution so your lambda expression is never being executed, because you're calling Select
but never using the results. This is why, everything work fine after calling .ToList()
just after calling GenerateEnumerableTest()
method:
var tab = CTest.GenerateEnumerableTest().ToList();