That's probably the easiest way to do it. Probably best write it with
two Hashtables (Dictionary<>s in 2.0), and leave it like that until you
get to performance optimization.
If you have *a lot* of data, it may not be the most efficient. If you
find that you're constrained, most likely by memory but also maybe
slightly by performance, you could try one of the following:
1. Create your own collection data structure that contains a master
collection in a data structure, and parallel searchable data structures
as the indices. It's up to you to guarantee referential integrity
between the indices and the master structure. This is complicated but
will give you the best performance if you design it right.
2. Use some sort of DataSet. Various project parameters will determine
if a typed DataSet is appropriate. You'll be able to perform selects
against it based on any key. I've never used them, but I believe you
may even be able to add indices. You get the generic DataSet overhead,
but it's rather efficient in most cases.
Stephan
Dustin Campbell wrote:
Like this I have a collection of objects and I need to retrieve a
record based on the passed Employee id or employee name. Looping
through an arraylist is too slow. And there is no dictionary available
to combine both keys. So I need to maintain two dictionary classes if
I want it faster.
Is there any better way to find the record faster?
Well, you could just add the same item to a Hashtable twice with different
keys.
Best Regards,
Dustin Campbell
Developer Express Inc.