C # collect and organize collections

Source: Internet
Author: User

New article: Automatic Web Browser| Old article: 6 common collection classes of C #


Stringcollection, array, arraylist, ilist, item, queue, stack, hashtable,Sortedlist


The arraylist.
Use stack when you need a set that can implement the following.
When you need a set of first-in-first-out, use queue.
If you need an array that can be queried by key value, use hashtable.
Sortedlist.
Csdn help:

Be careful when selecting Class. The incorrect type may restrict your use of the set.

Consider the following:

  • Do you need a sequence list where elements are generally discarded after retrieving their values?

    • If necessary, consider using Class or Generic class. Use Class or Generic class.

    • If not, consider using other collections.

  • Do I need to access elements in some order, such as FIFO, lifo, or random access?

    • QueueClass andQueueGeneric classes provide FIFO access.

    • StackClass andStackGeneric classes provide LIFO access.

    • Generic classes allow sequential access from the beginning to the end or from the end to the beginning.

    • Other sets provide random access.

  • Do I need to access each element through indexes?

    • And Class and Generic classes provide access to elements through the element index starting from scratch.

    • , , And Class and And Generic classes provide access to elements through element keys.

    • And Class and And A generic class provides access to an element through its element index starting from scratch or through its element key.

  • Will each element contain a combination of values, keys, and values, or a combination of keys and values?

    • One Value: Use any Interface or A set of generic interfaces.

    • One key and one value: Use any Interface or A set of generic interfaces.

    • A value with an embedded key: Use Generic class.

    • One key and multiple values: UseNamevaluecollectionClass.

  • Do I need to sort elements in a different way than the input element method?

    • HashtableClasses are sorted by the hash code of their elements.

    • SortedlistClass andSorteddictionaryAndSortedlistGeneric classes Interfaces and The implementation of generic interfaces sorts elements by buttons.

    • ArraylistProvide Method, which acceptsIcomparerImplementation as a parameter. Its corresponding generic class (ListGeneric class) provides Method, which acceptsIcomparerThe implementation of generic interfaces is used as parameters.

  • Do you need quick search and retrieval of information?

    • For small sets (10 or fewer items ),ListdictionaryRatioHashtableFast.SorteddictionaryRatio of generic classesDictionaryFaster query of generic classes.

  • Do I need to accept only the string set?

    • Stringcollection(Based onIlist) AndStringdictionary(Based onIdictionary) Are located in Namespace.

    • In addition, you can specify Class, you can use Any generic collection class in the namespace serves as a set of Strong string types.

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.