在Integer数组级别中获取逗号分隔的整数列表的最简单/最佳实践方法是什么?
Dim levels(5) As Integer
Dim levelsStr As String
'put values in levels'
'Attempt 1: Failed'
levelsStr = String.Join(", ", levels) ' <- Error on levels'
'Value of type "1-dimensional array of Integer" cannot be converted'
'to "1-dimensional array of String" because "Integer" is not derived'
'from "String".'
答案 0 :(得分:11)
试试这个
levelsStr = String.Join(", ", levels.Select(Function(x) x.ToString()).ToArray())
答案 1 :(得分:2)
以下是使用Array.ConvertAll执行此操作的方法:
Dim converter = New Converter(Of Integer, String)(Function(num) num.ToString)
Dim y = String.Join(", ", Array.ConvertAll(x, converter))