c# - Invert array of arrays -
i have string[][]. each entry in list represents column in document, each fellow member of array represents line in column. example:
0.0 | 1.0 | 2.0 0.1 | 1.1 | 2.1 0.2 | 1.2 | 2.2 now write file. if first need convert them string[] each element 1 line, joined let's commas (.csv file).
any suggestions how that?
i tried wrapping head around several loops taking n-th element of each column , stuff in buffer , bring together these buffers together. sure work way, don't think in way efficient or style.
if you're starting this:
string[][] original = new[] { new[] { "0.0", "0.1", "0.2" }, new[] { "1.0", "1.1", "1.2" }, new[] { "2.0", "2.1", "2.2" } }; then can work each row in turn:
for (int column = 0; column < original.length; column++) { string row = string.join(",", original.select(o => o[column])); console.writeline(row); } this yields next output:
0.0,1.0,2.0 0.1,1.1,2.1 0.2,1.2,2.2 c# arrays jagged-arrays
No comments:
Post a Comment