为什么程序会跳过foreach循环 [英] Why program skips the foreach loop

查看:178
本文介绍了为什么程序会跳过foreach循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach (EndReasonEntity ere in ste.EndReason)
 {
   if (ere.Id == endReasonId)

 foreach (EndReasonActivityEntity erae in ere.EndReasonActivity)




在上面的代码中,两个id在if条件中匹配,但它仍然没有进入它下面的另一个foreeach循环.而是跳过了整个循环,这是为什么?我需要一个清晰的解释.




in the above code the both ids match in the if condition , still it does not go in to the other foreeach loop which is right below it. instead it skips the whole loop ehy is that? i need a clear explanation please.

推荐答案

首先,您怎么知道它真的被跳过了?您的代码示例不完整,因此即使不跳过循环,我也看不到您的循环是否有效.因此,使用调试器可以肯定地说.现在,检查ste.EndReasonere.EndReasonActivity是否包含任何项目.如果您自己创建迭代器的类型,如何知道迭代器的实现是否正确?因此,再次在调试器下运行此命令以确保.

—SA
First, how do you know it really skipped? You code sample is not complete, so I cannot see if your loops have any effect even if it is not skipped. So, use the debugger to say for sure. Now, check if and when ste.EndReason and ere.EndReasonActivity have any items. If you created the iterators their types by yourself, how do I know if the iterators are correctly implemented? So, again, run this under debugger to make sure.

—SA


这篇关于为什么程序会跳过foreach循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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