最近,我遇到了一种情况,集合理论和集合数学完全符合我正在做的事情(假设有一种更简单的方法来完成我需要的东西 - 即 LINQ - 但我当时没有想到这一点)。但是我不知道有任何通用集库。当然 IEnumerables 提供了一些集合操作(并集等),但没有像交集或集合比较这样的操作。谁能指出适合这里的东西吗?使用泛型类型实现集合数学的东西?
Recently I came across a situation where set theory and set math fit what I was doing to the letter (granted there was an easier way to accomplish what I needed - i.e. LINQ - but I didn't think of that at the time). However I didn't know of any generic set libraries. Granted IEnumerables provide some set operations (Union, etc.), but nothing like Intersection or set comparison. Can anyone point out something that fits here? Something that implements set math using a generic type?
发布评论
评论(2)
框架 (3.5+) 中有
HashSet
可以满足您的需要。 .NET 4 还引入了SortedSet
和通用接口ISet
。There is
HashSet<T>
in the framework (3.5+) that does what you need. .NET 4 also introducedSortedSet<T>
and a common interfaceISet<T>
.System.Collections.Generic.HashSet 有许多集合操作,包括子集、超集、交集、并集等。
http://msdn.microsoft.com/en-us/library/bb359438.aspx
我希望这对
乔有帮助
System.Collections.Generic.HashSet has a number of set operations including Subset, Superset,Intersection,Union etc.
http://msdn.microsoft.com/en-us/library/bb359438.aspx
I hope this helps
joe