唯一列表在.NET 2中
什么是
- 最好的通用;
- .NET 2 的唯一(IComparable/IEquitable) 值
对象集合?
(à la List
,或 .NET 3.5 中的 HashSet
的等效项,但没有有序项)
What is a
- preferably generic;
- unique(IComparable/IEquitable) valued
collection of objects for .NET 2?
(à la List<T>
, or an equivalent of HashSet<T>
from .NET 3.5, but without ordered items)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 Iesi 中定义的
HashedSet
集合.Collections 组装。这是一个开源项目,NHibernate 也使用它。
You can use the
HashedSet<T>
collection that is defined in the Iesi.Collections assembly.This is an open source project, which is also used by NHibernate.
我们曾经在 .NET 2 中使用 PowerCollections Set 类。它运行得很好。图书馆里有很多好东西。
We used to use PowerCollections Set class for that in .NET 2. It worked quite well. There was a lot of nice stuff in the library.
不幸的是,第一个好的框架类是 HashSet,您可以使用它只能通过 .Net 3.5 访问。
如果您被困在以前的版本中,那么选项就不那么好了。最常见的是使用字典类型,其中键是您要存储的值。您可以相当轻松地将其包装在您自己的类中。
如果您愿意完全脱离框架,可以使用 .Net 的数据结构集合,例如 N泛型。
Unfortunately, the first good framework class for this is the HashSet, which you will only get access to with .Net 3.5.
If you are stuck in previous versions., the options are not as nice. The most common is to usea Dictionary type where the Key is the value that you are trying to store. You can wrap this in your own class fairly easily.
If you are willing to go outside the framework all together, there are collections of data structures for .Net, such as NGenerics.
你需要的是一个 Set,据我记得 2.0 中没有 Set 实现。您可以查看此。
编辑:如果你真的想实现自己的,类似这样的事情会以牺牲插入性能为代价来完成这项工作:(我没有测试该功能)
What you need is a Set, as far as I remember there was no Set implementation in 2.0. You can check this out.
Edit: If you really want to implement your own, something like this would do the job in expense of performance on inserts: (I did not test the functionality)