Pages

Friday, August 30, 2013

Difference between IEnumerable, ICollections, IList in C#

Here i would like to pint out the differences between IEnumerable, ICollection, IList

IEnumerable:
    Its the core interface used to iterate over the collection of specific types. It mainly implements the following methods:
    1. MoveNext: Which is of Boolean type which tells whether there are more records to move or not.
    2. GetCurrent: Which returns the current record from the collection.

 ICollection:
    Its an interface used to manipulate generic collections. It basically implements IEnumerable. Thus it will also implement the IEnumerable methods. Also it implements the following methods:
    1. Add: Add record at the end of the record.
    2. Remove: Remove the specified item from the collection.
    3. Contains: It is a Boolean type method which tells whether the collection contains the specified item or not.

 IList:
    Its an interface which is an collection of non generic type of objects and can be accessd by index. It implements IEnumerable and ICollection. Thus it will also implement the methods of IEnumerable, ICollection. Also it implements the following methods:
     1. Insert: Insert the specified item at the specified index.
     2. RemoveAt: Removes the item from the specified index.
     3. IndexOf: Retrieves the item from the index specified.