2012-08-09 90 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