How can I shorten List <List <KeyValuePair <string, string >>>?
5 answers
Both Listand Dictionaryare quite effective, so I would not have to think twice to use them. (If you are not going to keep gazillion dictionaries on your list, but this is not very common.)
, List<Dictionary<string, string>> ,
using LoDSS = System.Collections.Generic.List<System.Collections.Generic.Dictionary<string, string>>;
, , .
+3
, , , . , .
( ), , - ( ):
public class MyDictionary
{
private Dictionary<string, string> values;
public MyDictionary()
{
values = new Dictionary<string, string>();
}
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];
}
}
0
For clarity, I would turn yours KeyValuePair<string, string>into something shorter, for example. StringPair, and also define an abbreviation for the list StringPair. This will shorten your syntax and help read IMHO.
public class StringPair : KeyValuePair<string, string> { }
public class StringPairList : List<stringPair> { }
..
var jaggedList = new List<StringPairList>();
0