【发布时间】:2010-02-17 19:47:49
【问题描述】:
假设我有一个 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
【问题讨论】:
标签: c# .net dictionary functional-programming composition