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,
2 Answers
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).
List<string, string>doesn't exist. That's the main advantageList<KeyValuePair<string,string>>keywhich is not unique is ... eh ... an unfortunate name, don't you think? And eventually it can lead to confusion.