Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iterating a list with ForEach

I have a list like this

Dim emailList as new List(Of String)
emailList.Add("[email protected]")
emailList.Add("[email protected]")
emaillist.Add("[email protected]")

How can I iterate the list with ForEach to get one string with the emails like this

[email protected];[email protected];[email protected]
like image 326
Saif Khan Avatar asked Dec 18 '22 02:12

Saif Khan


2 Answers

I'm not sure why you would want to use a foreach instead of a String.Join statement. You could simply String.Join() the list using a semi-colon as your joining character.

String.Join(";", emailList.ToArray())
like image 102
NebuSoft Avatar answered Jan 14 '23 06:01

NebuSoft


You can try

Dim stringValue As String = String.Join(";", emailList.ToArray)

Have a look at String.Join Method

like image 38
Adriaan Stander Avatar answered Jan 14 '23 06:01

Adriaan Stander