如何从VB.Net 3.5中的对象列表创建连接字符串

时间:2012-04-27 00:58:38

标签: vb.net linq

我想我应该使用'聚合',但显然我错了

首先,我获得了一个实体对象列表

    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 ......”

任何线索?

3 个答案:

答案 0 :(得分:4)

请改为尝试:

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

答案 1 :(得分:0)

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

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

答案 2 :(得分:-1)

尝试:

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