我有一个数据表
ID RS
1484 1751
1668 15277
1677 3925
1484 1214
1668 7940
1677 696
1484 1849
1668 7781
1677 484
1484 1395
1668 5715
1677 416
&安培;我想要在应用Linq Group by和Binding 2维数组
之后得到以下结果 var a = new string[][] {
new[] { "1484 ","[1751, 1214, 1849, 1395]" },
new[] { "1668" ,"[15277, 7940, 7781, 5715"} ,
new[] { "1677","[3925,696, 484, 416}
};
答案 0 :(得分:1)
试试这个:
var a =
items
.ToLookup(x => x.ID, x => x.RS)
.Select(x => new []
{
x.Key.ToString(),
String.Format("[{0}]", String.Join(", ", x))
})
.ToArray();
这让我:
答案 1 :(得分:0)
您需要根据字段ID
var result = (from d in data
group d by d.ID into gr
select new
{
ID = gr.Key,
DataList = gr.ToList()
}).ToList();
您可以在此处获取分组值列表。
答案 2 :(得分:-2)
试试这个
Datacontexts db=new Datacontext();
var query=from i in db.table group by ID select new{i.Id,i.Rs};