Differences between. NET 2.0 generic collection classes and. NET 1.1 Collection classes (1)
3. Interfaces
The icollection with the largest changes in the interface <t>. In 1.1, icollection is a read-only version, and there is no way for you to modify the data in the set, however, the method for modifying data and the isreadonly attribute are added to the generic icollection <t>. I am sorry that I have not found the generic read-only version of icollection.
Icollection <t> although data can be modified, it does not support indexing, so it defines the ilist <t> interface, it inherits from icollection <t> and provides the digital retrieval function.
In terms of compatibility with the collection interfaces of earlier versions, ienumerable <t> supports ienumerable, icollection <t> does not support icollection, and ilist <t> does not support ilist.
System. collections. generic. idictionary <tkey, tvalue> is not much different from the old dictionary. At the inheritance level of the interface, the original idictionary is inherited from icollection, it is still the corresponding generic version of icollection <t>, but because icollection <t> adds the data modification function, it brings some trouble, because the dictionary requires the add method to pass in the key and value parameters, while the icollection add can only have one parameter, the icollection <t> is restricted to: icollection <keyvaluepair <tkey, tvalue> to provide two parameters.
The dictionary interface also adds trygetvalue (tkey, tvalue). This method is mainly used to improve performance. If you want to obtain a key location safely, you must use containskey (tkey) search for existence first, and then use this to search. In this case, there are two retrieval processes. The current trygetvalue will only be retrieved once.