我有课:
public class MyKeyValuePair
{
public string Key;
public string Value;
...
}
我想知道是否有比这更好的方法:
MyKeyValuePair myList;
Dictionary<string,string> dict;
foreach(var pair in dict)
{
myList.add(new MyKeyValuePair(pair.Key, pair.Value))
}
Linq方法
var result = dict.Select(x => new MyKeyValuePair() { Key = x.Key, Value = x.Value }).ToList();