which data type

G

Guest

Hi whats the best way to do this in vb.net:

I want to have basically a table of librarian name (string) and thier ID#
(integer) then i want to be able to quickly look up the number and get the
corresponding name and visa versa using the name get the ID.

Someone suggested collections, these are new to me and i don't seem to be
able to lookup the number. Isn't there a really simple way to do this? Should
i create a whole new class?

Thanks so much for any help you can give.
 
H

Herfried K. Wagner [MVP]

Jimbo1299 said:
I want to have basically a table of librarian name (string) and thier ID#
(integer) then i want to be able to quickly look up the number and get the
corresponding name and visa versa using the name get the ID.

You may want to use two hashtables ('Hashtable').
 
J

Joep

quickly look up on either name or id

leads to

where does the id come from? do you control its generation? relevant since
quickly calls for order and by using name to generate the id you can have
pairs (name1, id1) and (name2, id2) for which name1 < name2 is equivalent
with id1 < id2 and vice versa and so on

without such generation you either relax the requirement based on use and
use an arraylist with a type that implements IComparable for either name or
id whichever makes the most sense, a hash table is another option in this
case

if you need to have both name as well as id ordered you need two indices,
possibly two array lists like above but now with the requirement to keep
them 'in sync'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top