c# - Flatten List<string[]> into single string with one line for each element -


i have instance of type list<string[]> convert string each string[] on newline. i'm using following linq query flatten out list i'm not sure how can add new line between each string[] without expanding query far more ugly. there way without gutting query , using string.join or ienumberable.aggregate inside foreach loop?

results.selectmany(x => x).aggregate((c, n) => c + ", " + n) 

string.join(environment.newline, results.select(a => string.join(", ", a))); 

complete sample:

var results = new list<string[]> {     new[]{"this", "should", "be", "on"},     new[]{"other", "line"} };  var result = string.join(environment.newline,                           results.select(a => string.join(", ", a))); 

result:

this, should, be, on other, line 

update here aggregation done right - uses stringbuilder build single string in memory

results.aggregate(new stringbuilder(),                   (sb, a) => sb.appendline(string.join(",", a)),                   sb => sb.tostring()); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -