You may use the ConvertAll method of List object to convert the List(of Integer) to List(of String) and then generate a comma separated string. Here is the code to call ConvertAll method:
Private
Sub Form1_Load(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.LoadDim intList
As New List(Of
Integer)
intList.Add(1)
intList.Add(2)
intList.Add(3)
intList.Add(4)
Dim StringList
As List(Of
String) = intList.ConvertAll(New Converter(Of
Integer, String)(AddressOf ConvertIntToString))For
Each st As
String In StringList
Console.WriteLine(st)
Next
End Sub
Public Function ConvertIntToString(ByVal i
As Integer)
As String
Return i.ToString()
End Function
Marked as answer by Vince Xu - MSFT on Feb 11, 2008 08:12 AM
Andrew_C1
Member
619 Points
101 Posts
Re: convert list to comma separated string
Feb 05, 2008 09:18 PM|LINK
Hi Peter,
You may use the ConvertAll method of List object to convert the List(of Integer) to List(of String) and then generate a comma separated string. Here is the code to call ConvertAll method:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadDim intList As New List(Of Integer)intList.Add(1)
intList.Add(2)
intList.Add(3)
intList.Add(4)
Dim StringList As List(Of String) = intList.ConvertAll(New Converter(Of Integer, String)(AddressOf ConvertIntToString))For Each st As String In StringListConsole.WriteLine(st)
Next End Sub Public Function ConvertIntToString(ByVal i As Integer) As String Return i.ToString() End Function