Talk about the difference between list and IList in C # (reprint)

Source: Internet
Author: User

first, the IList generic interface is a descendant of the ICollection generic interface and is the base interface for all generic lists. 

but it is only the interface of all generic types, and there are not too many methods can be convenient and practical, if only as a set of data bearer, it is true that,ilist<t> can be competent.

However, more often, we want to process the collection data, filter the data, or sort it. At this time ilist<t> will be helpless.

1, when you only want to use the interface method,ilis<> this way is better. He does not acquire other methods and fields that implement this interface, effectively saving space.

2, IList <> is an interface, defines a number of operating methods these methods to you to achieve

List <> is a generic class that has implemented the IList <> defined methods

IList <Class1> IList11 =new List <Class1> ();

list <Class1> List11 =new list <Class1> ();

these two lines of code, from the operational point of view, are actually creating an instance of a List<class1> object, that is, their operation is not different.

only the return value variable type used to hold this operation is different.

So, we can understand that these two lines of code are different in purpose.

list <Class1> List11 =new list <Class1> ();

is to create a list<class1>, and you need to use the list<t> function to do the work.

and

IList <Class1> IList11 =new List <Class1> ();

just want to create an instance of an object based on interface ilist<class1>, but this interface is implemented by list<t>. So it just wants to use the functionality specified in the Ilist<t> interface.
PS: Reproduced in Baidu know only for my study and use

Talk about the difference between list and IList in C # (reprint)

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.