5

我想我应该使用“聚合”,但显然我弄错了

首先,我得到一个我的 Entity 对象的列表

    Dim employers As List(Of myEntity) = (New XXXX()).getZZZ(userName, userType)

然后我想这将是一种将所有名称放在字符串中的方法

    Dim names as String = employers.Aggregate(Function(current, [next]) current.Name & " " & [next].Name)

但我得到错误:“无法将类型'lambda表达式'转换为参数类型'System.Func(MyEntity,myEntity,myEntity......”

任何线索?

4

3 回答 3

9

试试这个:

Dim names = String.Join(" ", employers.Select(Function(employer) employer.Name))

于 2012-04-27T01:06:07.183 回答
0
Dim names as String = employers.Aggregate("", Function(current, [next]) current & " " & [next].Name)
' Use this                                ^^                                  ^^

之后您可能想要修剪字符串,因为它将以空格开头。

于 2012-04-27T01:04:34.553 回答
0

尝试:

Dim names as String = employers.Select(Function(emp) emp.Name ).Aggregate(Function(current, [next]) current & " " & [next])
于 2013-11-26T08:03:53.867 回答