IDictionary.Add 方法
2013/3/11
在 IDictionary 对象中添加一个带有所提供的键和值的元素。
程序集: mscorlib(位于 mscorlib.dll 中)
| 异常 | 条件 |
|---|---|
| ArgumentNullException | key 为 null。 |
| ArgumentException | IDictionary 对象中已存在具有相同键的元素。 |
| NotSupportedException | IDictionary 为只读。 - 或 - IDictionary 具有固定大小。 |
下面的代码示例演示如何实现 Add 方法。此代码示例是为 IDictionary 类提供的一个更大示例的一部分。
public void Add(object key, object value) { // Add the new key/value pair even if this key already exists in the dictionary. if (ItemsInUse == items.Length) throw new InvalidOperationException("The dictionary cannot hold any more items."); items[ItemsInUse++] = new DictionaryEntry(key, value); }