Working on an application, there is a need for collections of information (addresses, clients, etc.). How are you guys handling these tasks? My thoughts were to put my collection of objects (such as a collection of State objects) into some type of key-value
paired list. I started down the path of using Hashtables, but they do not offer any sorting functionality. SortedList will do sorting, but you must determine what you want to be your 'key' or sort value. Well, if you have duplicates, you would have two 'keys'
that are the same, which would violate the idea of a 'key'. ArrayList has sorting built in, but doesn't offer key-value pairs. What are you guys doing? Thanks, in advance. Charley.
Both, depending how many keys you have. As a rule I always start with an ArrayList, and then add Hashtables for each business key. Example... ArrayList employees; Hashtable employeesBySSN; Hashtable employeesByFirstNameLastName;
By definition, a hash does not have any order. Its items are stored in a random sequence. Only the array list has order, which you can sort. The hashtable's only purpose is to index the items by a key value. That's why you need both. I should mention you could
wrap this all up in your own collection class. A couple of advantages... * strong-typed Add and Get. * the Add method, besides adding the item to the array list, can also handle inserting the key values into each hash. This wraps up all of you logic in one
place. * If the key values in your hashtables are of different datatypes, you could overload the indexer. Otherwise you'll have to make methods like GetBySSN(int ssn).
Charley Bogw...
Participant
1880 Points
374 Posts
Passing of objects... How are you doing it?
Sep 15, 2003 02:42 PM|LINK
Stephen Vaki...
Contributor
2540 Points
508 Posts
Re: Passing of objects... How are you doing it?
Sep 15, 2003 03:10 PM|LINK
SoulOfRealit...
Participant
775 Points
155 Posts
Re: Passing of objects... How are you doing it?
Sep 15, 2003 07:20 PM|LINK
Charley Bogw...
Participant
1880 Points
374 Posts
Re: Passing of objects... How are you doing it?
Sep 15, 2003 07:44 PM|LINK
SoulOfRealit...
Participant
775 Points
155 Posts
Re: Passing of objects... How are you doing it?
Sep 16, 2003 04:56 AM|LINK