kartal kartal - 3 months ago 28
C# Question

Converting from IEnumerable to List

I want to convert from

IEnumerable<Contact>
to
List<Contact>
. How can I do this?

Answer

You can do this very simply using LINQ.

Make sure this using is at the top of your C# file:

using System.Linq;

Then use the ToList extension method.

Example:

IEnumerable<int> enumerable = Enumerable.Range(1, 300);
List<int> asList = enumerable.ToList();