IEnumerable and .Where Linq method behaviour?

前端 未结 2 1375
南旧
南旧 2021-01-17 21:25

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

2条回答
  •  孤城傲影
    2021-01-17 22:07

    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();
    

提交回复
热议问题