Convert List<int> to string of comma separated values

var nums = new List<int> {1, 2, 3};
var result = string.Join(", ", nums);

var ints = new List<int>{1,3,4};
var stringsArray = ints.Select(i=>i.ToString()).ToArray();
var values = string.Join(",", stringsArray);

Another solution would be the use of Aggregate. This is known to be much slower then the other provided solutions!

var ints = new List<int>{1,2,3,4};
var strings =
            ints.Select(i => i.ToString(CultureInfo.InvariantCulture))
                .Aggregate((s1, s2) => s1 + ", " + s2);

See comments below why you should not use it. Use String.Join or a StringBuilder instead.

Tags:

C#

List