Converting from IEnumerable to List

kartal picture kartal · Oct 1, 2011 · Viewed 400.6k times · Source

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

Answer

vcsjones picture vcsjones · Oct 1, 2011

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();