Given a List<int> how to create a comma separated string?
Given a List<int> how to create a comma separated strin开发者_运维百科g?
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"
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.
精彩评论