2012-08-09 80 views
-1

我需要閱讀集合內的集合並返回json結果或者我的linq或feach?閱讀集合在linq集合內

from col1 in collection1 select new{}{col1.field1, col1.field2, } 

讀collection2在col1和現在做的每一行的數字字段的總和,並返回到json

+0

這個問題還不夠清楚。請澄清並添加詳細信息。 – 2012-08-09 15:54:06

回答

0

如果我已閱讀並正確破譯你的問題,我認爲你正在尋找:

var collectionOfSums = from col1 in collection1 
         select new { 
         SumOfField1 = field1.Sum(), 
         SumOfField2 = field2.Sum(), 
         ... 
         SumOfFieldN = fieldN.Sum() 
         };  

我假設field1field2 ... fieldN是一組已知的。然後使用您喜歡的任何技術JSON -ify collectionOfSums

+0

如何從collection1中的collection2中讀取? – user1480864 2012-08-09 16:37:04

+0

它的樣子: collection1 [0] // o:index ----- Collection2 [2] // 2行數 collection1 [1] // 1:索引 ----- collection2 [4] // 4行數 – user1480864 2012-08-09 16:38:53

+0

所以這是一個二維數組? – bluevector 2012-08-09 16:57:55