Is the CollectionBase class supported?

I want to create a class that inherits from CollectionBase , but it looks like it does not support LINQ extensions!

Is it supported? Or is there an alternative solution?

+8
collections c #
source share
2 answers

It is still supported, but it is deprecated. You should always use collections defined in the System.Collections.Generic or System.Collections.ObjectModel namespaces, instead.

You can inherit one of the common collections to create your own, strongly typed collection. And it will have full LINQ support, as they already implement IEnumerable<T> .
Either List<T> or Collection<T> are good options for your case.

Avoid non-original collections like CollectionBase , ArrayList and HashTable , if at all possible. There is a performance penalty for using them, and they offer several advantages (if any!) In the generic versions that were introduced in later versions of the framework.

+23
source share

Linq extensions are written for IEnumerable<T> (Generic) and CollectionBase (Non-generic) are not inherited from it. That is why you cannot use Linq on it.

Use System.Collections.ObjectModel.Collection<T> instead.

+3
source share

All Articles