【发布时间】:2010-09-21 01:12:14
【问题描述】:
看System.Collections.Generic.Dictionary<TKey, TValue>,它显然实现了ICollection<KeyValuePair<TKey, TValue>>,但没有所需的“void Add(KeyValuePair<TKey, TValue> item)”功能。
在尝试像这样初始化 Dictionary 时也可以看到:
private const Dictionary<string, int> PropertyIDs = new Dictionary<string, int>()
{
new KeyValuePair<string,int>("muh", 2)
};
失败了
方法 'Add' 没有重载需要 '1' 个参数
为什么会这样?
【问题讨论】:
-
{new KeyValuePair
("muh", 2)}
标签: c# .net dictionary interface