Swap two lists in c# -


this question has answer here:

i have list of list (a matrix, sent via web.api http post matlab).

list<list<decimal>> mylist; 

the size of matrix nxm, how can swap lists? i.e.

mylist[i][j] --> mylist[j][i] 

in matlab operation mylist' or in mathematical context (transposing)

mylist^t  

you use linq achieve without for loop this:

var swapedlist =     mylist    .selectmany((l, i) => l.select((d, j) => new { i, j, d }))    .groupby(l=>l.j)    .select(l=>l.select(ll=>ll.d).tolist());    .tolist(); 

i hope helpful :)


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -