-4

I have to store list of two values similar to <string,string> and it is not like key,value.I can store it in objects or list,but whats the best way to store such data structures? I have seen few persons referring to use List<Tuple<string, string>> but what is the advantage of using above over other data structures like hashtable or object,

F11
  • 3,318
  • 10
  • 40
  • 74

2 Answers2

2

If you want a "key" to correspond to multiple values and efficiently find those values, then you can use Dictionary<string, List<string>>. This will be hashtable lookup by key into a list of values, so finding the values for a key will be O(1).

If you want to correlate the keys and values but don't need to look up by key then you can use List<Tuple<string, string>> or List<KeyValuePair<string, string>> if that suits you better, which you can iterate through and look up by index, but searching for a key will be O(N).

Tim
  • 5,545
  • 1
  • 8
  • 18
0

Make a new class with two string properies and put it in the List instead of Tuple<string, string> or anything else weird construct. Main advantage is that everybody else knows whats inside the list and you dont have two magic strings. Cleanest and easiest way.

Mighty Badaboom
  • 5,609
  • 5
  • 27
  • 47