Array and arraylist

Source: Internet
Author: User

1. Array

Public abstract class array: icloneable, ilist, icollection, ienumerable, istructuralcomparable, istructuralequatable

{

//////////////////

}

Array: The length is constant (fixed length). The data elements in the array are of the same type. It can be said that array is a set of the same data type.

Eg:

Int32 [] array = new int32 [5];

Int32 [] array = new int32 [] {2, 3, 4}; // The array size is determined based on the number of data elements in the initialization device.

 

2. arraylist

Public class arraylist: ilist, icollection, ienumerable, icloneable

{

//////////////

}

The length can be dynamically changed, and the data elements can be of different types (Value Type and reference type). It can be said that arraylist can be a set of multiple data types.

Arraylist arrlist = new arraylist ();

// Use the following two methods to add/delete elements and dynamically change the length. The parameters of these two methods are of the object type. If the input parameter is of the value type (valuetype, boxing operations may occur, resulting in slow running and lossy performance,

Eg:

Public Virtual int add (object value );

Public Virtual void remove (Object OBJ );

 

3. List <t>

Public class list <t>: ilist <t>, icollection <t>, ienumerable <t>, ilist, icollection, ienumerable

{

//////////////

}

It is a wildcard Equivalent Class of the arraylist class and has enhanced functions. You can use the following two methods to add/delete elements and dynamically change the length. The parameters of both methods are generic, boxing is not performed, so list <t> is in. NET 2.0 or above can completely replace arraylist, and more should be used list <t>

Eg:

Public void add (T item );

Public bool remove (T item );

---------- In addition, all types inherited from the ienumberable interface (or ienumerable <t> generic interface) can be enumerated, that is, you can use foreach to traverse every element in the set.

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.