I want to store an list of key value pair lists in a lightweight structure. This seems too cumbersome. What\'s better? Does List
If you are accessing the values by the key, use dictionary, that is what is meant for. To reduce the overhead of the dictionaries, try and give them an initial capacity.
Alternatively (if both lists are rather small), you could implement a custom hashing object, something like this (except prettier):
public class MyDictionary
{
private Dictionary values;
public MyDictionary()
{
values = new Dictionary();
}
public void Add(int index, string key, string value)
{
int hash = ((0xFFFF) & index) * (0xFFFF) + (0xFFFF) & key.GetHashCode();
values.Add(hash, value);
}
public string Get(int index, string key)
{
int hash = ((0xFFFF) & index) * (0xFFFF) + (0xFFFF) & key.GetHashCode();
return values[hash];
}
}