ToObservableCollection<T>()

using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace System.Linq
{
    public static class Enumerable
    {
        public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> enumerableList)
        {
            return enumerableList != null ? new ObservableCollection<T>(enumerableList) : null;
        }
    }
}
Example:
var list = new List<Employee>()
var oc = new List<Employee>()
 
// add some employees
 
oc = list.OrderBy(emp => emp.Salary).ToObservableCollection();

Description

Convert a IEnumerable<T> to a ObservableCollection<T> and can be used in XAML (WPF, Silverlight, Windows Phone & Windows Store) projects

Details

Double click on the code to select all.

 

;