IEnumerable
IEnumerable is an interface which is implemented to support the ForEach semantics of Microsoft Visual Basic. It contains GetEnumerator method therefore exposes the enumerator, which in turn performs a simple iteration over a collection of specified type.
Syntax of IEnumerable:-
public interface IEnumerable
Public method of IEnumerable:-
IEnumerator GetEnumerator();
Example of IEnumerable:-
Consider a list in C#:
List<int> ages = new List<int>();
ages.Add(10);
ages.Add(20);
ages.Add(30);
ages.Add(40);
ages.Add(50);
Converting this list to IEnumerable:-
IEnumerable<int> age_IEnumerable = (IEnumerable<int>)ages;
foreach (int age in age_IEnumerable)
{
Console.WriteLine(age);
}
0 Comment(s)