调试一个IEnumerable方法 [英] Debugging an IEnumerable method

查看:170
本文介绍了调试一个IEnumerable方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有回报的方法的的IEnumerable< T> 我试图来调试方法内的代码

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

我每次经过调试期间,在Visual Studio中执行代码,它的步骤在有问题的方法。

Each time I step through the code in Visual Studio during debug, it steps over the method in question.

当我把方法中的断点它从来没有被击中。该代码是肯定跑,因为我已经通过收益回报率从方法ING假T的测试。

When I place a breakpoint inside the method it never gets hit. The code is definately running as I've tested by yield return'ing fake T's from the method.

时它不可能调试IEnumerable的方法,这种方法还是我做别的事情了?

Is it not possible to debug IEnumerable methods this way or am I do something else wrong?

推荐答案

这方法只当您使用被击中在IEnumerable的项目。请记住,IEnumerable的延迟加载的项目,所以只是因为你调用返回了IEnumerable的方法,并不意味着方法实际上是获取调用在这一点上。如果你想让它变得右打,当你调用它,添加了ToList()在你的方法调用的末尾:

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

这篇关于调试一个IEnumerable方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆