6

我已经尝试了几种方法,每次尝试时都会出错。

这是使用带有 asp.net(forms) 和 vb.net 的 .net 3.5。

例子:

Dim _registrations = New List(Of Integer)

Dim regList As String

Dim ListOfReg = _registrations.convertall(Of String)(Function(i As Integer) i.ToString())

regList = String.Join(",", ListOfReg.ToArray())

错误信息:

Overload resolution failed because no Public 'convertall' can be called with these arguments: 'Public Function ConvertAll(Of String)(converter As System.Converter(Of Integer,String)) As System.Collections.Generic.List(Of String)': Argument matching parameter 'converter' cannot convert from 'VB$AnonymousDelegate_0(Of Integer,String)' to 'Converter(Of Integer,String)'.

其他尝试:

regList = String.Join(",", (_registrations.Select(Function(reg) reg.ToString()).ToArray()))

错误信息:

Public member 'Select' on type 'List(Of Integer)' not found.

任何帮助表示赞赏。

谢谢。

4

1 回答 1

20

这应该可以,我猜是选择中的方括号?

.NET 3.5 解决方案

Dim integers As List(Of Integer) = New List(Of Integer)
integers.Add(1)
integers.Add(2)
integers.Add(3)

Dim commas As String = String.Join(",", integers.[Select](Function(i) i.ToString()).ToArray())

MessageBox.Show(commas)

下面是.NET 4.0解决方案

Dim integers As List(Of Integer) = New List(Of Integer)
        integers.Add(1)
        integers.Add(2)
        integers.Add(3)


        Dim commas As String = String.Join(",", integers.ToArray)

        MessageBox.Show(commas)
于 2012-08-27T19:47:22.810 回答