The IEnumerable interface exposes the enumerator,
which supports a simple iteration over a collection of a specified type.
Namespace: System.Collections.Generic.
While using IEnumerable
List
is a
built in class that implements IEnumerableThis is a collection where we specify the type of data which will be handled by the Collection.
List<string>
objNames = new List<string>();
objNames.Add("Name1");
objNames.Add("Name2");
objNames.Add("Name3");
foreach (string
strName in objNames)
{
Console.WriteLine(objNames);
}
Notice that unlike the ArrayList example, all the elements in this example have the same type string.
No comments:
Post a Comment