【发布时间】:2010-10-12 12:19:26
【问题描述】:
我正在阅读(考虑编写我自己的线程安全字典)我发现了以下实现。
http://devplanet.com/blogs/brianr/archive/2008/09/26/thread-safe-dictionary-in-net.aspx
总体上看起来还不错,但有一件事让我感到困惑。
以下内容: 无法枚举线程安全字典。相反,枚举键或值集合
在这两个中都可以找到
public virtual IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
throw new NotSupportedException("Cannot enumerate a threadsafe dictionary. Instead, enumerate the keys or values collection");
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotSupportedException("Cannot enumerate a threadsafe dictionary. Instead, enumerate the keys or values collection");
}
我不明白为什么可以枚举键或值,但不能枚举字典的 kvp?
有人可以帮我解释一下吗?提前致谢。
【问题讨论】:
标签: c# dictionary