簡體   English   中英

Dictionary.ElementAt方法在某些類中可見,但在其他類中不可見

[英]Dictionary.ElementAt method is visible in some classes, but not others

我有一個字典,其中我需要迭代並進行更改。 我不能使用foreach語句,因為它有時會拋出InvalidOperationException,說在收集期間無法修改集合。

我可以使用for循環,結合Dictionary.ElementAt方法,並且我在其他類中成功使用它,但是在這個特定的類中,無法找到方法ElementAt! 有任何想法嗎?

ElementAtSystem.Linq.Enumerable中定義的擴展方法

您需要添加using子句才能使其可見:

using System.Linq;

請注意,Dictionary <TKey,TValue>上的ElementAt沒有多大意義,因為字典實現不保證元素具有任何特定順序,也不保證如果您對元素進行更改,順序不會改變字典。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM