Debugging an IEnumerable method

前端 未结 2 1048
忘了有多久
忘了有多久 2021-02-06 23:40

I have a method with returns an IEnumerable and I\'m trying to debug the code inside that method.

Each time I step through the code in Visual Studi

2条回答
  •  失恋的感觉
    2021-02-07 00:29

    That method only gets hit when you use the items in the IEnumerable. Remember, IEnumerable lazy loads the items, so just because you're calling the method that returns the IEnumerable, doesn't mean the method is actually getting called at that point. If you want it to get hit right when you call it, add a ToList() at the end of your method call:

    var result = myEnumerableMethod().ToList();
    

提交回复
热议问题