Selection of object containers

Source: Internet
Author: User

In programming, container objects are inevitably used to accommodate a certain number of objects. Microsoft's. NET programming platform is really convenient. It provides an arraylist object to meet most of the container object requirements during programming. But is that true?

Arraylist mainly provides an index-based container, but it also provides the contains function, so that you can write the function by content, but this is not necessarily efficient. In fact, in many cases, it is easier to use a key-based container to reduce traversal, and the function efficiency will obviously increase a lot.

The following are some experiences:

  1. Arraylist meets most requirements;
  2. The queue or stack is used only when it needs to be deleted after reading;
  3. If you need access based on keys rather than indexes, You need to select hashtable-multiple elements or listdictionary-a small number of elements;
  4. Do not use collection classes with redundant features;

Modify according to the four principlesCodeThe memory required for code running is significantly reduced, especially the memory peak, which is greatly reduced.

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.