Collection class in C #

Source: Internet
Author: User

1. The interfaces in system. colloctions that indicate the behavior of a set include:
1) icollection
Defines the size, enumerative number, and synchronization method of all sets. Derived from ienumerable
It defines the most basic behavior of the Collection class, and all the collection classes implement this interface (basic interface)
However, its behavior is too basic: it is mainly a count attribute. It doesn't make much sense to implement it independently.

2) ienumerable
Public enumeration number, which supports simple iteration on the set
It only has one getenumerator () method. This method can return an ienumerator interface through which the set can be traversed.
Basically, all the collection classes have implemented this interface.

3) ilist
Ilist is a set of values that can be sorted and accessed by indexes. It implements the icollection and ienumerable interfaces.
Is the abstract base class of all lists. There are three types of ilist implementation: Read-only, fixed size, and variable size.

4) idictionary
Idictionary is a set of key/value pairs. It implements the icollection and ienumerable interfaces.
Is the base interface of the set of key/value pairs. There are three types of idictionary implementations: Read-only, fixed size, and variable size.
Idictionary can be called a dictionary, ing, or hash. It accesses values based on keys (any type ).

------------------------------

2. The collection classes that can be directly used in system. collections include:
1) arraylist
Implemented interfaces: ilist, icollection, and ienumerable
As long as the set is not modified, arraylist supports multiple readers at the same time safely.
With the addition of elements to the arraylist, the capacity increases automatically by reallocation as needed (2 times increase)
If you need to create an object array but do not know the size of the array in advance, you can use arraylist
Arraylist references all elements as object objects. Therefore, type conversion is required when accessing the elements of arraylist.
Advantages: dynamic resizing, flexible and convenient insertion and deletion of elements, and sorting
Disadvantage: The insertion performance is not as good as that of an array or a strong type.

2) bitarray
Implemented interfaces: icollection and ienumerable
Manage the compressed array of bits.

3) hashtable
Implemented interfaces: idictionary, icollection, and ienumerable
You can add or delete elements to or from hashtable. Some elements are like arraylist, but they do not have such high performance overhead.

4) sortedlist
Implemented interfaces: idictionary, icollection, and ienumerable
Sortedlist combines the advantages of arraylist and hashtable, and can be sorted by pressing values.

5) queue
Implemented interfaces: icollection and ienumerable
Queque is a queue for first-in-first-out access to various elements.
You can call the getenumerator () method of the queque object to obtain the ienumerator object and traverse each element in the queue.

6) Stack
Implemented interfaces: icollection and ienumerable
A stack is a stack, followed by first-in-first-out access to each element.
You can call the getenumerator () method of the stack object to obtain the ienumerator object and traverse each element in the stack.

For example, you can simply traverse the items in the arraylist.

Protected Arraylist subordinates;
Ienumerator enumsub = Subordinates. getenumerator ();
While (Enumsub. movenext ()) {< br> esub = (employee) enumsub. current;
sum += esub. getsalaries ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.