gpt4 book ai didi

asp.net - 整数列表到逗号分隔的字符串

转载 作者:行者123 更新时间:2023-12-01 22:57:17 25 4
gpt4 key购买 nike

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

这是将 .net 3.5 与 asp.net(forms) 和 vb.net 一起使用。

例子:

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.
任何帮助表示赞赏。

谢谢。

最佳答案

这应该有效,我猜是选择上的方括号?

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

关于asp.net - 整数列表到逗号分隔的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12148045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com