1

I need a fast lookup function that will return a string based on an integer key, and also perform the oppose lookup (pass in string, return int).

Should I create 2 hashtables for this?

dove
  • 20,469
  • 14
  • 82
  • 108
mrblah
  • 99,669
  • 140
  • 310
  • 420
  • 1
    If your integer key is compact enough (mostly inclusive of 0 thru N) then I would use string[] or List to map the integers to the string. As others said, use the Dictionary for the reverse. – csharptest.net Sep 22 '09 at 16:41

2 Answers2

5
Dictionary<int, string> lookup = new Dictionary<int, string>();
lookup.Add(1, "test1");
lookup.Add(2, "test2");
lookup.Add(3, "test3");

If you need to do fast lookups both ways, you could make 2 of them.

Larsenal
  • 49,878
  • 43
  • 152
  • 220
4

A Dictionary is what you want, and plenty of related answers to help.

Though hardly a definitive answer without more information, will the strings be unique for instance?

Community
  • 1
  • 1
dove
  • 20,469
  • 14
  • 82
  • 108