元素列表已更改。枚举操作无法继续。 [英] The element list has changed. The enumeration operation failed to continue.

查看:29
本文介绍了元素列表已更改。枚举操作无法继续。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除节点的子节点。在执行foreach循环期间,我遇到错误 - 元素列表已更改。枚举操作无法继续。我想因为我正在更改XML文件我遇到了这个错误,但不知道如何修复它。有人可以更正我的代码吗?

I am trying to delete the child nodes of a node. During the execution of the foreach loop I am having an error- "The element list has changed. The enumeration operation failed to continue." I think because I am changing the XMLfile I am having that error but dont know how to fix it. Can someone correct my code?

推荐答案

当你在集合上使用 foreach 尝试使用<$时,通常会发生这种情况c $ c>代替。



编辑:

This usually happens when you use foreach on your collections try using for instead.


foreach(var x in collection)
{
...
}
// becomes
for(int i=0;i<collection.length;i++)
{
...
}


这篇关于元素列表已更改。枚举操作无法继续。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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