Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String separating in list

I have a list called listitems which contains information on items.

I want to separate each list item by a comma and put it in a string called gh

But when I use the following I get the output as :

",a,b" which is incorrect

but I want the output as "a,b".

How can I modify the code ?

foreach(var a in listitems)
{
  gh = gh +"," + a;
}
like image 258
user1907849 Avatar asked Dec 12 '22 19:12

user1907849


1 Answers

string gh = String.Join(",", listitems); //
like image 117
L.B Avatar answered Jan 01 '23 10:01

L.B