What does the interface IEnumerable do in C#?

CsharpProgrammingServer Side Programming

IEnumerable is an interface defining a single method GetEnumerator() that returns an IEnumerator interface. It is the base interface for all non-generic collections that can be enumerated.

This works for read-only access to a collection that implements that IEnumerable can be used with a foreach statement.

It has a single method −

  • GetEnumerator() − This method returns an enumerator that iterates through a collection.

The following is the implementation of the GetEnumerator() method of the IEnumerable interface in C# −

IEnumerator IEnumerable.GetEnumerator() {
return (IEnumerator) GetEnumerator();

The following are the extension methods of the IEnumerable interface in C# −

Sr.NoMethod Name & Description
Enables parallelization of a query
The method converts an IEnumerable to an IQueryable.
The method casts the elements of an IEnumerable to the specified type
Filters the elements of an IEnumerable based on a specified type.
Published on 09-Aug-2018 10:40:18