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"
"123213123"
and I want to get
"123123123213,1232113213213,123213123"
I was wondering what is the best way to achieve that.
I could do this like this:
private List<string> stringList = new List<string> {
// a lot of strings in here
"1234567890", "34343434", "4343434" };
string outcome = string.Join(",", stringList.ToArray());
Or maybe:
StringBuilder builder = new StringBuilder();
stringList.ForEach(val => {
builder.Append(val);
builder.Append(",");
});
string outcome = builder.ToString();
Which way is better? Do you know better ways to concatenate strings?