Freely convert between List<T> and IEnumerable<T>

TK. picture TK. · Jan 23, 2009 · Viewed 161.7k times · Source

How can I convert a List<MyObject> to an IEnumerable<MyObject> and then back again?

I want to do this in order to run a series of LINQ statements on the List, e. g. Sort()

Answer

Tamas Czinege picture Tamas Czinege · Jan 23, 2009
List<string> myList = new List<string>();
IEnumerable<string> myEnumerable = myList;
List<string> listAgain = myEnumerable.ToList();