Original link: http://blog.csdn.net/shanyongxu/article/details/47005979
Collection Interfaces and types
The interfaces implemented by arrays and array classes are described earlier . The size of the array is fixed . If the number of elements is dynamic , the collection class should be private .
List<t> is a collection class that is equivalent to an array . There are other types of collections : queues , stacks , lists, and dictionaries .
Most collection classes can be found in the system.collections and System.Collections.Generic namespaces . The generic collection class is located in the System.Collections.Generic namespace ; Collection classes that are dedicated to specific types are located in the System.Collections.Specialized namespace . Thread-Safe collection classes are located in the System.Collections.Concurrent namespace .
The interfaces for collection and list implementations are as follows :
Interface |
Description |
Ienumerable<t> |
If The foreach statement is used for a collection, the IEnumerable interface is required . This excuse defines the method GetEnumerator (), He returns an enumeration that implements the IEnumerator interface |
| Icollection<t> |
Icollection<t> interface has a generic collection class implementation . Use this excuse to get the number of elements in the collection (Count properties Copy the collection into the array (CopyTo () method ", You can also add and remove elements from the collection (ADD () , Remove (), Clear ()) |
| List<t> |
Ilist<t> Interface for the list of elements that can be accessed through a location , This interface defines an indexer , You can insert or delete mount some (Insert () remove () method interface derived from icollection<t > interface |
| Iset<t> |
Iset<t> The interface is The new . The set of implementations of this interface allows merging of different sets . Get the intersection of two sets , check whether two collections overlap . Iset<t> interface derived from icollection<t > interface |
Idictionary<tkey,tvalue> |
the Idictionary<tkey,tvalue> interface is implemented by a generic collection class that contains keys and values . With this interface, you can access all keys and values , you can access certain items by using an indexer with key types , and you can add or remove items |
Ilookup<tkey,tvalue> |
The ilookup<tkey,tvalue> interface is similar to the idictionary<tkey,tvalue> interface, which implements a set of keys and values for that interface. And can contain multiple values through a single key |
| Icomparer<t> |
Interface icommparer<t> implemented by comparator , |
| Iequalitycomparer<t> |
Interface iequalitycomparer<t>, This comparator can be used in dictionaries for keys . Use this interface , You can compare objects for equality . In .net , |
Iproducerconsumercolllection<t> |
the Iproducerconsumercollection<t> interface is . Added in NET4 , it supports new thread-safe collection classes |
C # Programming (47)----------collection interfaces and types