user1306322 user1306322 - 1 month ago 5
C# Question

Convert list of objects to string in one line

I have a list of objects that implement

ToString()
. I need to convert the whole list to one string in one line. How can I do that?

Answer

Another method that may help out is string.Join, which takes a set of objects and will join them with any delimiter you want. For instance:

var combined = string.Join(", ", myObjects);

will make a string that is comma/space separated.