Possible Duplicate:
most elegant way to return a string from List<int>
I'm not sure the easiest way to do this. I simply want to add a ; between each value and spit it out as one string. I don't see that you can do this with ToString(). I'd have to loop through and create a stringbuilder and append & add a ";".
string.Join(";", myList.ToArray());
UPDATED to use List<int>
instead of List<string>
Use string.Join
:
List<int> data = ..; var result = string.Join(";", data); // (.NET 4.0+) var result = string.Join(";", data.Select(x => x.ToString()).ToArray()); // (.NET 3.5)
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