C# combine to list in json object -
i have 2 lists of string:
list<string> tmpcols = new list<string>(); list<string> tmprows = new list<string>();
e.g. tmpcols = [a,b,c]; , tmprows = [x, y];
i need iterate both list , json result this:
new matrix() { id = "1", col = "a", row = "x" }); new matrix() { id = "2", col = "b", row = "x" }); new matrix() { id = "3", col = "c", row = "x" }); new matrix() { id = "4", col = "a", row = "y" }); new matrix() { id = "5", col = "b", row = "y" }); new matrix() { id = "6", col = "c", row = "y" });
the dimension in case 2 rows , 3 columns.
this textbook example of nested loop. loops can contain other loops, inner 1 repeats each element of outer one. 1 might like:
var result = new list<matrix>(); var count = 1; foreach (var r in tmprows) foreach (var c in tmpcols) result.add(new matrix { id = (count++).tostring(), col = c, row = r });
Comments
Post a Comment