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

ToList<T>

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

Source

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;
}

Example

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: 2163