Tutorial :Join Array Of Integers



Question:

What is the simplest/best practices way to get a comma separated list of the integers in the Integer array levels?

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".'  


Solution:1

Try this

levelsStr = String.Join(", ", levels.Select(Function(x) x.ToString()).ToArray())  


Solution:2

Here's how you could do it with Array.ConvertAll:

Dim converter = New Converter(Of Integer, String)(Function(num) num.ToString)  Dim y = String.Join(", ", Array.ConvertAll(x, converter))  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »