Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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

like image 449
Blankman Avatar asked Jul 04 '10 16:07

Blankman


People also ask

How do you make a comma separated string from a list in Python?

How to Convert a Python List into a Comma-Separated String? You can use the . join string method to convert a list into a string. So again, the syntax is [seperator].

How can I convert an array to comma separated string?

To convert an array to a comma-separated string, call the join() method on the array, passing it a string containing a comma as a parameter. The join method returns a string containing all array elements joined by the provided separator. Copied!


1 Answers

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"
like image 159
dtb Avatar answered Oct 18 '22 17:10

dtb