Closed as an exact duplicate of this question .
I have an array / list of elements. I want to convert it to a string separated by a custom separator. For example:
[1,2,3,4,5] => "1,2,3,4,5"
What is the shortest / best way to do this in C #?
I always did this by looping through the list and checking to see if the current item is not the last before adding a separator.
for(int i=0; i<arr.Length; ++i) { str += arr[i].ToString(); if(i<arr.Length) str += ","; }
Is there a LINQ function that can help me write less code?
arrays c # linq
Loris Dec 19 '08 at 11:17 2008-12-19 11:17
source share