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

前端 未结 1 1839

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 t

相关标签:
1条回答
  • 2021-02-13 22:33

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

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

    using System.Linq;
    

    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.

    0 讨论(0)
提交回复
热议问题