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


Convert a IEnumerable<T> to a ObservableCollection<T> and can be used in XAML (Silverlight and WPF) projects


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

namespace Databinding01 {
    public static class CollectionExtensions {

        public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> coll) {
            var c = new ObservableCollection<T>();
            foreach (var e in coll)
            return c;


var list = new ObservableCollection<Employee>()

// add some employees

list = list.OrderBy(emp => emp.Salary).ToObservableCollection();

Author: Fons Sonnemans

Submitted on: 26 nov 2008

Language: C#

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

Views: 13405