难道CollectionBase的类仍然支持?CollectionBase

2023-09-02 23:56:49 作者:匆匆那年

我想创建一个类继承自CollectionBase,但它似乎不支持LINQ扩展!

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

它仍然支持?还是有一种替代解决方案?

Is it still supported? Or is there an alternative solution?

推荐答案

它仍然是的支持的,但它已经过时了。你应该总是preFER使用在System.Collections.Generic或System.Collections.ObjectModel命名空间,而不是。

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

您可以从通用集合来创建自己的自定义,强类型集合中的一个继承,也是如此。它将对LINQ的完全支持,因为他们已经实施的IEnumerable&LT; T&GT; 。 无论 名单,其中,T&GT; 或< A HREF =htt​​p://msdn.microsoft.com/en-us/library/ms132397.aspx> 收藏&LT; T&GT; 是不错的选择你的情况。

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

避免非泛型集合如 Col​​lectionBase的的ArrayList 的HashTable 如果在所有可能的。有性能上的损失,使用他们,他们也提供了一些优势(如果有的话!)在这是在该框架的较新版本推出的通用版本。

Avoid the non-generic collections like CollectionBase, ArrayList, and HashTable if at all possible. There is a performance penalty to using them, and they offer few advantages (if any!) over the generic versions that were introduced in more recent versions of the framework.

相关推荐