I really want to use hashsets in my program. Using a dictionary feels ugly. I'll probably start using VS2008 with .Net 3.5 some day, so my ideal would be that even though I can't (or can I?) use hashsets in VS2005, when I start using .NET 3.5, I don't want to have to change much, if anything, in order to switch to using these hashsets.
I am wondering if anyone is aware of an existing hashset implementation designed with this in mind, or a way to use the 3.5 hashset in VS2005.
You could use Iesi.Collections (used by NHibernate) or Mono's HashSet
Here's one I wrote for 2.0 that uses a Dictionary<T, object> internally. It's not an exact match of the 3.5 HashSet<T>, but it does the job for me.
The C5 Library also has a HashSet implementation.
You can alias the Dictionary as Hashset with a using directive. Not really the same thing, but it might simplify things for you later.
You can use
HashSet<T>
in a 2.0 application now - just reference System.Core.dll and you should be good to go.Note: This would require you to install the .NET 3.5 framework which is free and separate from Visual Studio. Once you have that installed you will have the new System.Core assembly which contains the
HashSet<T>
type. Since the .NET frameworks versions 2.0 - 3.5 all share the same CLR you can use this assembly in your 2.0 application without any issues.I think PowerCollections library should fit your needs. It's an open source library that contains several collection classes that were missing in .NET, including
Set<T>
,Bag<T>
,MultiDictionary
etc. It runs on .NET 2.0. I've been using it for couple of years now and I'm very pleased with it.