Sunday, June 16, 2013

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.


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.


QR: Inline image 1