Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert existing IEnumerable<int> to string (#,#,#,..) via Method

I'm trying to convert an IEnumerable<int> to a string in the format #,#,#,... I'm having a terrible time attempting to make a method of this. What is a quick and easy way to handle?

Thanks.

like image 228
Channing Avatar asked Nov 12 '13 20:11

Channing


2 Answers

Use String.Join:

string result = string.Join(",", enumerable);
like image 181
Servy Avatar answered Oct 22 '22 18:10

Servy


Are you talking about something like:

string.Join(",", e.Select(i=>i.ToString()).ToArray());

i.e., concatenating an enumerable of ints (e in this case)?

like image 26
Blindy Avatar answered Oct 22 '22 19:10

Blindy