c# - Remove duplicate from the following list using Linq -


i have class items properties (id, name, drugcode1, drugcode2).

the list of items populated duplicated items.

for eg.:

------------------------------------------ id        name     drugcode1  drugcode2 ------------------------------------------ 1         item1       2         3 2         item2       3         2 3         item3       4         3 1         item1       3         2 3         item3       3         4 

if durgcode1 , drugcode2 reversed consider items duplicates

eg:

1         item1       2         3 1         item1       3         2 

the above 2 itmes considered duplicate since drugcode1 , drugcode2 reversed. need fetch 1 item.

how remove duplicates in list using linq?

since have not tagged linq-provider presume linq-to-objects. use anonymous type in same order groupby:

ienumerable<item> distinctitems = items   .groupby(i => new { min=math.min(i.drugcode1, i.drugcode2),max=math.max(i.drugcode1, i.drugcode2) })   .select(g => g.first()); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -