In C#, if I have a List<MyObj>
where MyObj
is a custom class with an overridden ToString()
method such that each MyObj
object in the List can be easily converted to a string.
How can I join this List<MyObj>
with a delimiter, such as for example a pipe (|) into a single string.
So, if I had 3 MyObj objects whose ToString methods would produce AAA, BBB, CCC respectively. I would create a single string: AAA|BBB|CCC.
For a list of a simpler type, such as List<string>
, I perform this simply as: String.Join("|", myList.ToArray());
. Is there a way I can do something similar to that? Or am I forced to iterate over the Object List and use a StringBuilder to append each object's ToString in the list together?