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


This extentions method will convert the ObservableCollection object to List of underluying objects.


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

public static List<T> ToList<T>(this ObservableCollection<T> oc)
    var list = ((ICollection<T>)oc).ToList<T>();
    return list;


ObservableCollection<int> oc = new ObservableCollection<int>();

var list = oc.ToList();
var list1 = oc.ToList<T>();

ObservableCollection<TestObject> oc = new ObservableCollection<TestObject>();

var list = oc.ToList();
var list1 = oc.ToList<TestObject>();

Author: Muhammad Shoaib Ijaz

Submitted on: 25 nov 2021

Language: csharp

Type: System.Collections.ObjectModel.ObservableCollection<T>

Views: 47