http://www.codeproject.com/csharp/hashlistarticle.asp
Typically you get HashTable data via the Key, but it's very simple to
implement an iterator/enumerator. This should help.
Cheers,
Bill
This article doesn't show how to get an item from a HastTable by index.
That is not possible. HashTable does not even store the order in which
items were added, and there is no such thing as an index in a hashtable.
Items are stored in "buckets" which is what gives the Hashtable it's
speed. The drawback is that it cannot store an order to the items.
You can iterate any collection using an Enumerator that implements
IEnumerable. You can get an Enumerator using the "GetEnumerator()"
method on HashTable, but that does not return the items in any
particular order. And as you iterate an Enumerator you cannot modify
the collection.
What the article you provided does show is how to create a new type of
collection that has these capabilities. It also has an internal
HashTable and a separate internal ArrayList. This is the same concept as
I mentioned.
The differences:
My version inherits from CollectionBase which has the benefit of being
bindable to controls (because it implements IList). It is also strongly
typed for your custom object type that will be contained in the
collection.
HashList (from article) implements IDictionary which gives you some of
the extra properties of HashTable.
A mixture of both would be really good. I'll work on this and post a new
template for the simple code generator. This shouldn't take long. Check
the site later (see link in my signature).
--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/colcodegen (simple code generator)
http://sourceforge.net/projects/dbobjecter (database app code generator)
http://sourceforge.net/projects/genadonet ("generic" ADO.NET)