I need to concatenate a lot of strings alltogether and put a comma between any of them. I have a list of strings
\"123123123213\"
\"1232113213213\"
\"1232131
As @Ekkehard said, use the string.Join.
However, you do not need the ToArray()
because string.Join
has an overload for IEnumerable
.
List stringList = new List
{ "1234567890", "34343434", "4343434" };
string outcome = string.Join(",", stringList);
EDIT
As @Kobi said, this will work only C# 4.0. In 3.5 I would do.
var s = new StringBuilder(stringList.Count * 8);
foreach (var item in stringList)
{
s.Append(item);
s.Append(',');
}
s.Length -= 1;
string outcome = stringList.ToList();