假设我有一个 A 的任意列表
class A
{
string K {get;set;}
string V {get;set;}
}
...
List<A> theList = ...
有没有一种简单的方法可以从 theList 编写字典?(类似于以下内容)
Dictionary<string, string> dict = magic(x => x.K, x => x.V, theList)
我不想写下面的代码:
var d = new Dictionary<string, string>
foreach(var blah in theList)
d[blah.K] = blah.V