Datatable.select使行变得清晰

时间:2014-04-05 17:10:11

标签: c# datatable

我有这样的数据表:

Code    Class
A       Math
A       History
B       Math
B       Math

我想要具有相同代码值但类不相同的行。预期的事情:

A       math
A       History

我曾尝试过Datatable.select和Group By,但它不起作用!帮助我。

1 个答案:

答案 0 :(得分:1)

通过LINQ执行此操作的最简单方法应该是:

dataTable.Distinct()
         .GroupBy(x => x.Code)
         .Where(gr => gr.Count() > 1)
         .SelectMany(gr=> gr);
相关问题