1. Description of dictionary [Key] = "123" on msdn.
Http://msdn.microsoft.com/zh-cn/library/9tee9ht2 (V = vs.85). aspx
This attribute provides the ability to access specific elements in a collection using the following C # Syntax: mycollection [Key] (mycollection (key in Visual Basic )).
You can use the item attribute to add new elements by setting a key value that does not exist in the dictionary. When setting the attribute value, if the key is in a dictionary, the assigned value replaces the value associated with the key. If the key is not in the dictionary, the key and value are added to the dictionary. In contrast, the add method does not modify existing elements.
The key cannot be a null reference, but if the value type tvalue is a reference type, this value can be null.
2. The link of dictionary. Add (key, "123") on msdn.
Http://msdn.microsoft.com/zh-cn/library/k7z0zy8k (V = vs.85). aspx
3. Summary (dictionary. Add (key, "123") and dictionary [Key] = "123 ")
If the key already exists in the dictionary, the system returns the error "add": The dictionary has an element with the same key.
Dictionary [Key] does not report an error. If it is not added, it is changed or replaced. Therefore, it is recommended to use this method, which is safer without having to write an if statement.