IEnumerable, ICollection, IList, and List. Differences between ilist and list

Source: Internet
Author: User

IEnumerable, ICollection, IList, and List. Differences between ilist and list

First, let's take a look at IEnumerable:

// Abstract: // public enumerator, which supports simple iteration on a set of the specified type. //// Type parameter: // T: // type of the object to be enumerated. [TypeDependency ("System. SZArrayHelper")] public interface IEnumerable <out T>: IEnumerable {// Abstract: // returns an enumerator for a loop access set. //// Return result: // The System. Collections. Generic. IEnumerator that can be used to access the set cyclically <T>. IEnumerator <T> GetEnumerator ();}

IEnumerable <T> implements the IEnumerable interface method. What does IEnumberable do actually improve the set that can be accessed cyclically. To put it bluntly, it is an iteration.

Let's take a look at ICollection:

// Abstract: // defines the method for operating a generic set. //// Type parameter: // T: // type of the element in the set. [TypeDependency ("System. SZArrayHelper")] public interface ICollection <T>: IEnumerable <T>, IEnumerable

The original ICollection <T> inherits both the IEnumerable <T> and IEnumerable interfaces. In my understanding, ICollection continues with the two interfaces and extends the methods, which has more functions.
From the original rifle to the semi-automatic rifle

Let's continue to look at IList:

public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable

IList inherits the three interfaces. No wonder there are so many functions. It should be a fully automated rifle.

Finally, let's take a look at the List:

public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable

At this time, let's take a closer look. They are all interfaces. Only List is a class, which not only implements their interfaces, but also extends too many methods for me to use. Wow, almost all functions can be implemented. It's a laser rifle.

Sort by function: List <T> IList <T> ICollection <T> IEnumerable <T>

Sort by performance: IEnumerable <T> ICollection <T> IList <T> List <T>

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.