gpt4 book ai didi

vb.net - 如何将长列表转换为字符串数组? (VB)

转载 作者:行者123 更新时间:2023-12-03 00:45:32 27 4
gpt4 key购买 nike

我想将(Long)列表转换为字符串数组。

原因:它是数据库 ID 列表,我想将逗号分隔的字符串传递到存储过程中。

我尝试过这个:

Dim commaDelimitedList As String = String.Join(",", itemIDList.Cast(Of String)().ToArray)

但我显然没有正确使用 Cast,因为它引发了异常:System.InvalidCastException:无法将“System.Int64”类型的对象转换为“System.String”类型..

有没有办法让 Cast 为此工作,或者我是否坚持使用 ConvertAll 和委托(delegate)函数?

最佳答案

如果您可以使用 LINQ,这将执行您想要的操作:

Dim commaDelimitedList  As String = String.Join(",", itemIDList.Select(Function(itemID) itemID.ToString()).ToArray())

关于vb.net - 如何将长列表转换为字符串数组? (VB),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1626063/

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