What does the interface IEnumerable do in C#?

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.

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 20-Jun-2020

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started