What are the collections in C #?
Array
ArrayList
List<t>
Stack<t>
Queue<t>
Dictionary<k,v>
HashTable
Collection, which represents a set of objects that can be accessed by traversing each element (in particular, can be accessed using a Foreach Loop) A collection consists of multiple elements, namely, a collection class object and N element objects
Because any collection class implements the IEnumerable interface, any collection class object has a
The GetEnumerator () method, which returns an object that implements the IEnumerator interface, which returns a IEnumerator object that is neither a collection class object nor a collection's element class object, which is a separate class object. This object allows you to iterate through each element object in a collection class object.
If the collection class is a user-defined collection class, the user must implement its GetEnumerator () method, or the loop cannot be used. Of course, the IEnumerator class that corresponds to this custom collection class (the class that implements the interface) also needs to be customized.
For example, the IEnumerator that corresponds to the ArrayList collection class is the Arraylistenumeratorsimple array collection class corresponding IEnumerator is Szarrayenumerator (these two classes Not covered in the. NET Framework Class Library documentation (MSDN))
The interfaces that represent the behavior of the collection in 1.system.colloctions are: 1) ICollection
Defines the size, enumerator, and synchronization method for all collections. Derived from IEnumerable it defines the most basic behavior of the collection class, all of which implement this interface (the base interface) but its behavior is too basic: it's basically a Count property, it doesn't make much sense to implement it alone.
2) IEnumerable
Exposes an enumerator that supports simple iterations on the collection
It has only one method GetEnumerator (), and the method can return a IEnumerator interface through which the collection can be traversed
Basically all of the collection classes implement this interface 3) IList
An IList implementation is a collection of values that can be sorted and accessed by its members by index, which itself implements the ICollection and IEnumerable interfaces
is the abstract base class for all lists. There are three categories of IList implementations: read-only, fixed-size, variable-size.
4) IDictionary
The IDictionary implementation is a collection of key/value pairs that itself implements the base interface for ICollection and IEnumerable interfaces that are collections of key/value pairs. There are three categories of IDictionary implementations: read-only, fixed-size, variable-size. IDictionary can be called a dictionary, a map, or a hash table, which accesses a value based on a key (any type)
The collection classes that can be used directly in 2.system.collections are: 1) ArrayList
Interfaces are implemented: IList, ICollection, IEnumerable
ArrayList can safely support multiple readers at the same time as long as the collection is not modified
As you add elements to the ArrayList, the capacity is automatically increased (twice times increased) on demand by reallocation if you need to create an array of objects, but you cannot know the size of the array beforehand, you can use ArrayList
ArrayList all elements as object objects, so type conversions when accessing ArrayList elements
Pros: Dynamic resizing, flexible and convenient insertion and deletion of elements, sortable drawbacks: performance is inferior to arrays, not strongly typed
2) BitArray
Implements an interface: a compressed array of ICollection, IEnumerable management bit values.
3) Hashtable
Interface implemented: IDictionary, ICollection, IEnumerable
You can freely add and remove elements to Hashtable, some like ArrayList, but not so much performance overhead
4) SortedList
Interface implemented: IDictionary, ICollection, IEnumerable
SortedList takes into account the advantages of ArrayList and Hashtable, can be sorted by key values 5) Queue
Implements the interface: ICollection, IEnumerable Queque is the queue, FIFO access to each element
You can call the GetEnumerator () method of the Queque object to get the IEnumerator object to traverse each element in the queue 6) Stack
Implements interface: ICollection, IEnumerable stack is stack, last-in-first-out access to individual elements
You can call the GetEnumerator () method of the Stack object to get the IEnumerator object to traverse the elements in the stack
What are the collections in C #?