C # -- ilist, detailed explanation of the differences between arraylist and list

Source: Internet
Author: User

Commonalities:

Ilist, list, And arraylist are generally generalized arrays, which are called collections in C. Different from general narrow arrays, they can store any type of things and be specified when declaring or assigning values. For example, if you write a class cake and want to have a structure to store many cake instances, you can use them. Differences: In general, ilist and list can only store elements of the same type. For example, when declared as list <cake> cakes = new list <cake> (), you can only use an instance with cake. When an element is retrieved from the cakes variable, the cake type is obtained directly. You do not need to perform forced conversions, so the performance is better. If you want an 'array' to store various types of instances, such as cake, juice, and bread, use arraylist food = new arraylist (); note that it does not specify what type of elements it installs, so you can install them as needed ~ Of course, the benefits cannot be exhausted. When 'taobao' is used, it is troublesome. The elements in arraylist are of the object type by default. Therefore, forced conversion is required, which causes poor performance in big data.
The difference between ilist and list: In my understanding, ilist is an interface, and list is a definite class. Interface, of course, you need to implement its functions. If you want these functions to have their own characteristics, write a class for implementation! When the statement is made: ilist <type> KK = new your implemented class name <type> (); of course you can write it: ilist <type> KK = new list <type> (); It is equivalent to implementing ilist in list (in fact, this is defined in C # API) if you write a list <type> KK = new list <type> (), it means that your code, the functions that operate the list cannot be changed at all, and you have to follow the rules. You can use what you write. Usage: The usage of the preceding three sets is similar to that of Java. If there is a list <cake> cakes addition, deletion, modification, and query method:
 
Cakes. add (cake T); // Add cakes. remove (INT index); // Delete cakes. remove (cake T); // Delete cakes [] = // modified data // query or modify

Note: reposted from Sina BlogHttp://blog.sina.com.cn/s/blog_6cb117430100o0ul.html

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.