This is a textbook example of a nested loop. Loops can contain other loops, where the inner one repeats for each element of the outer one. This one might look something 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 });
solved C# combine to list in json object