ExtensionMethod.NET Home of 877 C#, Visual Basic, F# and Javascript extension methods


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


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;


var list = new List<Employee>()
var oc = new List<Employee>()
// add some employees
oc = list.OrderBy(emp => emp.Salary).ToObservableCollection();

Author: Farhan Ghumra

Submitted on: 10 jun. 2013

Language: C#

Type: System.Collections.Generic.IEnumerable<T>

Views: 4931