How to get distinct values from data table?

216 Views Asked by At

I am trying to return an `array with distinct records. But this piece of code isn’t working. What am I doing wrong?

return table.AsEnumerable().Distinct(DataRowComparer.Default).ToArray(); 
1

There are 1 best solutions below

3
Suresh Kaushik On
table
    .AsEnumerable()
    .GroupBy(row => row.Field<DataType>("FieldName"))
    .Select(group => group.First())
    .ToArray()