Given a List<int> how to create a comma separated string?
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].
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!
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With