I am in wpf, and have a generic list: List. Now I wish to cast it to a generic observable collections: ObservableCollection.
I understand I can iterate over the list and
you can do it by using extension method
public static ObservableCollection ToObservableCollection(this IEnumerable coll)
{
var c = new ObservableCollection();
foreach (var e in coll) c.Add(e);
return c;
}
or you can use this constructor The elements are copied onto the ObservableCollection in the same order they are read by the enumerator of the list.
ObservableCollection collection = new ObservableCollection(yourList);