Saturday, 18 May 2013

Difference between IEnumerable, ICollection and IList Intrefaces in C#

Difference between IEnumerable, ICollection and IList Intrefaces in C#

Below article demonstrates the difference between IEnumerable, ICollection and IList Intrefaces. IEnumerable interface is the core interface and is implemented by ICollection and IList. Lets have a look.

IEnumerable

Its a core interface which is used to iterate over collection of specified type. Mainly implements two methods:

MoveNext: which is of boolean type which tells whether there are more records to move on or not.

GetCurrent: which returns the current record from the collection.
 
ICollection: Implements IEnumerable

It is an interface used to manipulate generic collections, as it implements IEnumerable interface so its obvious that this will also implements methods MoveNext and GetCurrent, so with this interface you can iterate through collection. Apart from this its also having its own methods like:

Add: Adds record at the end of collection
Remove: Removes specified item from collection
Contains: Its a boolean type method which tells whether collection contains the specified item or not.

IList

Interface which is collection of non-generic type objects and can be accessed by index. It is the interface which implements two interfaces ICollection and IEnumerable. So its obvious that this will Implements the methods of the both the interfaces. Its own methods are:

Insert: Insert the given item at specified Index.
RemoveAt: Removes the item from specified Index.
IndexOf: Retrieves the item from specified Index.

8 comments:

  1. Simple and Direct. Excellent Article !!!

    ReplyDelete
  2. Very simple .. thanks .

    ReplyDelete
  3. Very useful ... Thankyou

    ReplyDelete
  4. Nice and... Best article,
    Thank U

    ReplyDelete
  5. vice nice. to the point and easy to understand. thanks

    ReplyDelete
  6. http://www.coachoutletstoreinc.com/ Coach Outlet Store Online
    http://www.michaelkorsoutletmkinc.com/ Michael Kors Outlet
    http://www.coachfactoryoutletwebsite.com/ Coach Factory Outlet
    http://www.tomsusashoes.com/ Toms Shoes
    http://www.cheapjerseysinc.com/ Cheap Jerseys
    http://www.michaelkors-bedford.com/ Michael Kors
    http://www.coachoutlet-sale.com/ Coach Outlet
    http://www.coachfactoryoutletorg.com/ Coach Factory Outlet
    http://www.coachoutlet-buy.com/ Coach Outlet
    http://www.coachhandbagsonlineoutlet.com/ Coach Handbags
    http://www.giuseppezanottionline.com/ Giuseppe Zanotti
    http://www.coachfactoryoutlet-handbags.com/
    http://www.coach-factory-outlet-online.com/ Coach Factory Outlet Online
    http://www.coachstoreonline.com/ Coach Outet Store Online
    http://www.coachfactoryoutlets2014.com/ Coach Factory Outlet
    http://www.michaelkorsoutletonlinemk.com/ Michael Kors Outlet Online
    http://www.celineoutlet-online.com/ Celine Outlet
    http://www.michaelkors.name/ Michael Kors
    http://www.michael-kors-outlet-store.com/ Michael Kors Store
    http://www.tomsshoescompany.com/ Tomss Hoes
    http://www.pradaoutlet-store.com/ Prada Outlet
    http://www.fitflopfootwear.com/ Fitflop Footwear
    http://www.celinebags-outlet.com/ Celine Bags
    http://www.fitflopsflipflops.com/ Fitflops Flipflops
    http://www.fitflopusaonline.com/ Fitflops
    http://www.giuseppezanottidesigner.com/ Giuseppe Zanotti Designer
    http://www.fitflopflip-flop.com/ Fitflops
    http://www.giuseppezanottisneakersmen.com/ Giuseppe Zanotti Sneakersmen
    http://www.fitflopsandalssale.com/ Fitflops

    ReplyDelete