c# - LINQ distinct is showing duplicates -
c# - LINQ distinct is showing duplicates -
i trying utilize linq find duplicates. have read, should utilize distinct
. query below finds duplicates in list, contains both original value , duplicate.
how can distinct items?
class macroconfig { public guid? guid { get; set; } public string name { get; set; } public string value { get; set; } } //this linq query using list<macroconfig> dupelist = macrolistwithduplicates.groupby(x => x.guid) .where(y => y.count() > 1) .selectmany(y => y) .distinct() .tolist(); foreach (var x in dupelist) { console.writeline(x.tostring()); }
distinct() homecoming distinct macroconfig objects, because macroconfig's distinct() receiving input. if want 1 item each guid, can select first item each group:
list<macroconfig> dupelist = macrolistwithduplicates .groupby(x => x.guid) .where(grp => grp.count() > 1) .select(grp => grp.first()) .tolist();
c# linq linq-to-xml
Comments
Post a Comment