如何在linq匿名函数内调用函数

时间:2011-08-17 08:05:16

标签: .net linq c#-4.0 anonymous-function

我想做那样的事情:

var result = genericList.ToDictionary(CalculateSomething(x => x.Date), y => y.Point);

因此,根据该示例,我想在CalculateSomething()

中呼叫.ToDictionary()

我有什么方法可以做到这一点,我可以通过foreach循环来做到这一点,但我想保持linq语法。

2 个答案:

答案 0 :(得分:2)

你的lambda语法错误了:

var result = genericList.ToDictionary(x => CalculateSomething(x.Date), y => y.Point);

答案 1 :(得分:2)

var result = genericList.ToDictionary(x => CalculateSomething(x.Date), y => y.Point);