Monday, June 3, 2013

IEnumerable T Interface

The IEnumerable interface exposes the enumerator, which supports a simple iteration over a collection of a specified type.


While using IEnumerable we provide the type along with the data, represents the type of data which will be stored in the collection.
List is a built in class that implements IEnumerable, any class which implements IEnumerable  interface should define the GetEnumerator method of the IEnumerable  interface, hence the items in the class can be queried using a foreach loop as follows.

This is a collection where we specify the type of data which will be handled by the Collection.

    List<string> objNames = new List<string>();


    foreach (string strName in objNames)

Notice that unlike the ArrayList example, all the elements in this example have the same type string.

Search Flipkart Products:

No comments: