Dictionary.ElementAt方法是可见的部分班级,而不是其他人 [英] Dictionary.ElementAt method is visible in some classes, but not others

查看:2082
本文介绍了Dictionary.ElementAt方法是可见的部分班级,而不是其他人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个解释,它的元素,我需要遍历并进行更改。我不能使用foreach语句,因为它有时抛出InvalidOperationException异常,说是集合不能在enumaration期间进行修改。

I have a Dictionary whose elements I need to iterate through and make changes. I cannot use foreach statement, since it sometimes throws InvalidOperationException, saying that the collection cannot be modified during an enumaration.

我可以用一个for循环,在字典一起。 ElementAt的方法,以及我成功地使用在其他类,但在这个特殊的类,该方法的ElementAt无法找到!任何想法?

I can use a for loop, in conjunction with Dictionary.ElementAt method, and I successfully used it in other classes, but in this particular class, the method ElementAt cannot be found! Any ideas?

推荐答案

ElementAt的是在的扩展方法 = http://msdn.microsoft.com/en-us/library/system.linq.enumerable_methods.aspx\">System.Linq.Enumerable 。

ElementAt is an extension method defined in System.Linq.Enumerable.

您需要添加一个使用条款,以使其可见:

You need to add a using clause to make it visible:

using System.Linq;



注意的ElementAt在字典< TKEY的,TValue>不会使一个很大的意义,不过,因为字典实现不保证元素在任何特定的顺序,也不是说,如果你更改了字典的顺序不会改变。

Note that ElementAt on a Dictionary<TKey,TValue> doesn't make a lot of sense, though, as the dictionary implementation does not guarantee elements to be in any specific order, nor that the order does not change if you make changes to the dictionary.

这篇关于Dictionary.ElementAt方法是可见的部分班级,而不是其他人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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