ASP. Ienumerable,icollection,ilist,list Differences

Source: Internet
Author: User

C # Students, all know that a class can only have one inheritance class, but can implement multiple interfaces. This sentence tells us: ienumerable,icollection,ilist,list difference

First I look at IEnumerable:

    Summary:    //Exposes an enumerator that supports simple iterations on a collection of specified types. ////    type parameter:    //   T:    //   type of object to enumerate.    [Typedependency ("System.szarrayhelper")] public    interface ienumerable<out t> : IEnumerable    {        //Summary:        //     Returns an enumerator that iterates through the collection. ////        return Result:        //     system.collections.generic.ienumerator<t> that can be used to iterate through the collection.        ienumerator<t> GetEnumerator ();    }  

ienumerable<t> implementation of IEnumerable interface method, that ienumberable do what, in fact, to improve the collection can be looped access. To be blunt is an iteration.

Look again at ICollection:

    Summary:    //     defines methods for manipulating generic collections. ////    type parameter:    //   T:    //     The type of the element in the collection.    [Typedependency ("System.szarrayhelper")] public    interface icollection<t>: ienumerable<t , IEnumerable

Originally icollection<t> at the same time inherit Ienumerable<t> and IEnumerable two interfaces, according to my understanding is, ICollection continue their 2 interfaces and extend the method, the function is much stronger.

Turned from the original rifle to a semi automatic rifle.

We continue to look at IList:

Public interface ilist<t>: Icollection<t>, Ienumerable<t>, IEnumerable

By the IList to inherit their three interfaces, no wonder the function so much ah, it should belong to the full automatic rifle

Finally, let's look at list:

public class list<t>: Ilist<t>, Icollection<t>, Ienumerable<t>, IList, ICollection, IEnumerable

This time people look closely, they are all interfaces, only the list is the class, not only to implement their interface, but also extended too many ways for me to use. Wow, almost everything is going to work, 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>

rule: The more functions, the lower the performance, so the general situation of MVC view page head using ienumerable<t> more

The pro can be called according to their own needs not array to implement the function, do not blindly use list, thank you!

ASP. Ienumerable,icollection,ilist,list Differences

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.