C # list<> contact with Array, ArrayList

Source: Internet
Author: User

Array:

Array must specify its size when initializing the object

Abstract class, cannot constructor instantiate an array (for example: array arr = new array[] error)

However, it is possible to initialize an array class array arr = new int[3]{1,2,3};

You can also use the CreateInstance method of the array class to initialize the array arr = Array.CreateInstance (typeof (int), 3) where an int array of 3 elements is defined

ArrayList:

You do not have to specify the size when initializing

After instantiating an object, you can add, delete, modify, and manipulate the elements in the object.

Efficiency itself is lower than array

List<>:

Before the. NET Framework 2.0, array representations can be expressed in array and collection Class ArrayList, and after 2.0,. NET introduces the concept of generics list<>, then we have a choice of one more.

For example, we define an int type list:list<int> List = new list<int> ();

The introduction of generics is intended to reduce the performance cost of the type of packing unpacking.

Similarly, we can do the same for elements in a list generic as in ArrayList

Note:

The efficiency of the array is higher than the list, when the length of the array is not very large, there is no difference between the two, it is recommended to use LIST<>, after all, is variable length, can add, special application or the proposed array, do not promote the use of ArrayList.

  

C # list<> contact with Array, ArrayList

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.