Converting ObservableCollection to List?
How does one convert an ObservableCollection
to a List
of the held objects?
Just need to add the namespace using System.Linq;
and use the method ToList()
in the ObservableCollection object
Depending on the type of object in the ObservableCollection
... I'll assume it's an int
for this example:
IEnumerable<int> obsCollection = (IEnumerable<int>)GetCollection();
var list = new List<int>(obsCollection);
Given that ObservableCollection<T>
implements IEnumerable<T>
you can give it to the constructor of List<T>
:
List<T> myList = new List<T>(myObservableCollection);
Where T
is the type of the items in the collection.
ObservableCollection
implements IList<T>
, so you should be able to use ToList()
on it.
http://msdn.microsoft.com/en-us/library/bb342261.aspx