Link to home
Start Free TrialLog in
Avatar of Jess31
Jess31

asked on

Linq Unique list ?

I am trying to get a list of unique ISBN as such
   Dim ISBNs = From row In dt Select row.Field(Of String)("ISBN").Distinct
But it is returning all including duplicates. What am doing wrong?
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Try it like this.[code]Dim ISBNs = (From row In dt
Select row.Field(Of String)("ISBN"))ToList()..Distinct()[/code]
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also make use of the morelinq library's DistinctBy method:

Dim ISBNs = dt.Rows.DistinctBy(Function (row) row.Field(Of String)("ISBN"))

Open in new window


You can install morelinq via NuGet.