观察 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' 个参数
为什么会这样呢?