Reputation: 267370
Given a List<int> how to create a comma separated string?
Upvotes: 14
Views: 4473
Reputation:
If it's going to be a large string, you may want to consider using the StringBuilder class because it is less memory intensive. It doesn't allocate memory each time you append another string, which yields performance improvements.
Upvotes: 0
Reputation: 217411
You can use String.Join:
List<int> myListOfInt = new List<int> { 1, 2, 3, 4 };
string result = string.Join<int>(", ", myListOfInt);
// result == "1, 2, 3, 4"
Upvotes: 33