难道CollectionBase的类仍然支持? [英] Is the CollectionBase class still supported?

查看:192
本文介绍了难道CollectionBase的类仍然支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个类继承自<一个href="http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.aspx"><$c$c>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使用在<定义的集合href="http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx"><$c$c>System.Collections.Generic或<一href="http://msdn.microsoft.com/en-us/library/system.collections.objectmodel.aspx"><$c$c>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.

这篇关于难道CollectionBase的类仍然支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆