Which Collection To Use?

  • Thread starter Thread starter Guadala Harry
  • Start date Start date
G

Guadala Harry

I'd like recommendations for which collection to use to store name/value
pairs. What I'm doing is retrieving a simple name/value pair list from the
database via stored procedure that returns the pairs in a specific order
(and never more than 25 name/value pairs). In the application, I need to be
able to store the name/value pairs and subsequently retrieve/enumerate them
*in the order returned by the stored procedure*. A SortedList obviously
won't work because it sorts automatically on the key value... Hashtable has
its own sorting going on. So, what can I use?

Thanks!
 
arraylist of name/value pairs will do I guess, possibly with some
compare/compareto thingy for lookup
 
Will you ever need to lookup a value by it's name?

If not (and you don't mention needing to), then just use an ArrayList of
DictionaryEntry.

If you do need it look them up, then why limit yourself to just one data
structure?
Place the Name/Values in a Hashtable, and the Names in an ArrayList.
When you need to iterator them in order, enumerate the ArrayList, to get the
Names, and then look up the Values in the hashtable.


--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
 
Very creative solutions to a surprising problem... I thought I was just
missing something obvious... but I guess it's the framework that's missing
something obvious! - thanks.

-GH
 
Back
Top