In this blog post, we will see how we can convert a List to IEnumerable in C#.
A List in C# already implements an IEnumerable but you may still feel the need to convert a List to IEnumerable in C#.
Let's see how we can do this.
C# List To IEnumerable Using .AsEnumerable() Method
Using Linq, we can use the .AsEnumerable() method in C# which is available to us on Lists.
Using this .AsEnumerable method, we can convert a list to Ienumerable.
Let's look at a code example.
var listOfColors = new List
Result:
orange red green pink
As you can see that we converted a list to IEnumerable in C# using the .AsEnumerable method.