user3487768
user3487768

Reputation: 1

Datatable.select get rows dulicate

I have datatable like this:

Code    Class
A       Math
A       History
B       Math
B       Math

I wanna rows which have same Code value but Class is not same. Something Expected:

A       math
A       History

I had tried Datatable.select and Group By , but it Dont work! Help me.

Upvotes: 0

Views: 53

Answers (1)

Tomas Pastircak
Tomas Pastircak

Reputation: 2857

Simplest way of doing this via LINQ should be something like:

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

Upvotes: 1

Related Questions