. NET Framework-arraylist's code explanation

Source: Internet
Author: User


In the previous section, when we introduced the data structure of array, we said that it was static, the number of elements per dimension was compiled, and it was uniquely determined, and its type was strongly typed.
So, in this section, we'll talk about another data structure similar to array but overcomes the disadvantage of array: ArrayList.
First of all, it is not static, at compile time the number of elements of each dimension is not specified, the system default element number is 16, when the element increases and is about to be greater than 16 o'clock, it will increase the expansion to 32, in order to increase the regular growth, change the hours, the opposite processing.
Second, the element type is a weak type, object. At run time, depending on the type that is actually given, the type of each element is determined, that is, the elements in this set can be a variety of different elements, mixed-style.
Look first. NET provides the ArrayList interface:

1) object creation and initialization

Object creation            ArrayList ArrayList = new ArrayList () {3.14, "vuefine"};            add element            arraylist.add ("Hello wolrd");            Arraylist.add (5);

2) Accessing elements

            Access Element            Object ELE0 = arraylist[0];            Type t0 = Ele0. GetType ();//double

3) Modifying elements

             Modify Element            arraylist[0] = "Ni Hao";

4) Delete Element

             Delete element            //Remove existing Object            Arraylist.remove (5);            Arraylist.removeat (0);            Remove objects that do not exist            Arraylist.remove (12);//Do not throw exceptions

5) ArrayList and other object relationships

            Object cloneal = Arraylist.clone (); Create a shallow copy of            Type Tclone = Cloneal.gettype ();                        Array is abstract and can only be created by static methods array array            = Array.CreateInstance (typeof (Object), Arraylist.count);             Arraylist.copyto (array);//Copy to array
Related Article

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.