开发者

Given a List<int> how to create a comma separated string?

开发者 https://www.devze.com 2023-01-05 12:08 出处:网络
Given a List<int> how to create a comma separated strin开发者_运维百科g?You can use String.Join:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消