ToObservableCollection

public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> collection)
{
  ObservableCollection<T> list = new ObservableCollection<T>();

  foreach (T item in collection)
  {
    list.Add(item);
  }

  return list;
}
Example:
ObservableCollection<object> filteredlist = (from object o in unfilteredlist select o).ToObservableCollection();

Description

Copies elements from IEnumerable<T> into ObservableCollection<T>. Handy for converting LINQ results into a list appropriate for WPF databinding.

Details

Double click on the code to select all.

 

;