Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-generic IEnumerable to string

Tags:

c#

There are a lot of questions/answers about conversion from generic IEnumerable to a string.

But I need a conversion from a non-generic IEnumerable to a string. The result string should be in form of
element1.ToString() + ", " + element2.ToString() + ", " + element3.ToString() + ...
Is there a shorter way than using StringBuilder and looping through the elements by MoveNext()?

like image 377
brgerner Avatar asked Aug 01 '26 04:08

brgerner


1 Answers

You can still use LINQ:

String.Join(", ", thingy.Cast<object>());
like image 93
SLaks Avatar answered Aug 03 '26 17:08

SLaks