1. icollection Interface
Arrays are the most basic collection types defined by. NET Framework. In addition to arrays,. NET Framework also defines many Collection types. Open msdn and you can see that all collections are in the system. Collections namespace:
Arraylist: use an array that can be dynamically increased by size to implement the ilist interface.
Bitarray: a compressed array of management values. This value indicates a Boolean value. True indicates that the bit is open (1), and false indicates that the bit is closed (0 ).
Caseinsensitivecomparer: checks whether two objects are equal. The case sensitivity of strings is ignored during comparison.
Collectionbase: Provides abstract base classes for Strongly typed sets.
Comparer: compare whether two objects are equal, where string comparison is case sensitive.
Dictionarybase: provides an abstract base class for a strongly typed set of key/value pairs.
Hashtable: a set of key/value pairs. These key/value pairs are organized according to the hash code of the key.
Queue: indicates the object's first-in-first-out set.
Readonlycollectionbase: provides an abstract base class for a strongly typed non-generic read-only set.
Sortedlist: a set of key-value pairs. These key-value pairs are sorted by key and can be accessed by index.
STACK: A simple post-first-out non-generic set of objects.
Icollection: defines the size, enumeration number, and synchronization method of all non-generic sets.
Icomparer: exposes a method for comparing two objects.
Idictionary: A non-generic set of key/value pairs.
Idictionaryenumerator: enumeration of non-generic dictionary elements.
Ienumerable: Public enumeration number, which supports simple iteration on a non-generic set.
Ienumerator: supports simple iteration of non-generic sets.
Iequalitycomparer: defines a method to support equal object comparison.
Ilist: A non-generic set of objects that can be accessed separately by index.
Let's take a look at the icollection interface and ienumerable interface.
This interface defines two main specifications for its implementation class:
(1) number of elements in the set, that is, the Count attribute;
(2) iteration (getenumerator method ).
The getenumertor method is inherited by the icollection parent interface ieumerable. The icollection interface defines a collection for storing and retrieving object-type object references. This allows you to store and obtain reference or value-type objects of various reference types.
This interface is the parent interface of icollection, which provides its implemented classes with the ability to iterate. The ieumerable interface has only one getenumerator method, and returns the number of enumerations for a loop access set.
Iteration, also called the iterator, is the iteration mode in the design mode. It provides a method to access each element in an aggregate object sequentially without exposing the internal representation of the object. Because the storage methods of the set are different, the list is continuous storage, and the reference storage between objects is used in the linked list ...... it is not convenient to traverse a set. You need a method that can traverse all different sets. This requires an iterator.
The iterator combines classes as a container with unlimited capacity, and the storage rules are linear. That is, in addition to the first and last elements, each element has a direct precursor and a direct successor. The container has a flag that can point to any storage unit in the container. There are two methods: one-way iteration and two-way iteration.
(1) unidirectional Iteration
One-way iteration refers to only Forward Iteration. The unit mark of a set can only be moved one by one from the beginning of an element of the set. Therefore, iteration defines three operations:
A. Current item
B. Go to the next item and determine if it is the end
C. Return to the initial item
(2) bidirectional iteration Mode
In bidirectional iteration mode, the Unit signs of a set move one by one from an item in the Set, or one by one from an item in the set. Therefore, there are four operations:
A. Current item
B. Move forward to the next item and determine whether or not to end
C. Return to the previous item and determine whether it is the beginning of the set.
D. Return the initial position.
. NET Framework uses the ieumerable interface to define a one-way iteration specification. The icollection interface inherits the ieumerable interface. The getenumerator method defined by this interface can obtain an iteration object of the current collection class object, that is, an object that implements the ieumerable interface.
All classes that implement the ienumerable interface can be iterated using foreach.
The ienumerator interface defines an iterator that can be referenced by objects of the object type. The ienumerable interface defines the method to obtain such iterative sub-objects.
3. Generic set
Icollection <t> Interface
The icollection <t> interface defines the generic set interface. The so-called generic set is used. net Framework provides a generic feature that limits a set to a set that only stores data of a specific type of object reference or value type. Generic collections enhance the efficiency and security of set access.
Because the storage type has been determined, icollection <t> provides more methods than the icollection interface, including adding to the collection, deleting from the collection, and determining an object reference (or object value) whether it exists in the set.
Ienumerable <t> Interface
The icollection <t> interface implements the ienumerable <t> interface, which is mainly used to return an iterative sub-object that implements the ienumerator <t> interface and determines the type.