I have a datatable, dtCpt
which has multiple columns in it. It has a column named CLAIM_NUMBER
.
I have a list List<long> claimNos;
I need all the distinct CLAIM_NUMBER
from datatable dtCpt
to the list claimNos
.
I write a code like this
claimNos = dtCpt.AsEnumerable().Select(s => new { id = s.Field<long>("CLAIM_NUMBER") }).Distinct().ToList();
but it show an error like this
Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List'
Is there any easy way to do this in a single line of code?
You don't need anonymous type at all. Try that:
claimNos = dtCpt.AsEnumerable()
.Select(s => s.Field<long>("CLAIM_NUMBER"))
.Distinct()
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With