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>