How do I convert a Generic IList<T> to IList?

Annoyingly, IList<T> is one of those interfaces which doesn't implement its non-generic counterpart IList.

If you can find a way to pass a List<T> rather than an IList<T> (or some other type which implements IList as well as IList<T>, such as ObservableCollection<T>), that's going to be easiest. This might mean changing your application so that you pass a List<T> or something else around rather than an IList<T>.

Otherwise, you might have to create a new List<T> using the elements in the IList<T>, and pass that (i.e. myList.ToList()). Note that this means that you've created a copy of your list, and so changes to the original won't be reflected in the copy. In particular, ListCollectionView checks to see whether the source collection implements INotifyCollectionChanged, and subscribes to collection changed events if so: this obviously won't work if you create a copy of your list.


List<T> implements IList (IList<T> does not). Create a List<T> from your IList<T> and pass that to the ListCollectionView constructor:

ListCollectionView lcv = new ListCollectionView(new List<YourType>(yourIList));

Tags:

C#

Wpf