简体   繁体   中英

exclude an element from a grouping

I am looking for duplicates in a dictionary of type Dictionary<long, MyClass> using MyClass.some_property as the comparison value:

var dict = new Dictionary<long, MyClass>(...);
var duplicates = from d in dict
                 group d by d.Value.some_property into g
                 where g.Count() > 1
                 select g;

Now I need to exclude the first element in each grouping in the duplicates enumerable. How is this done without converting everything to another data structure? I want to avoid using any additional memory.

You can use skip

var dict = new Dictionary<long, MyClass>(...);
var duplicates = from d in dict
                 group d by d.Value.some_property into g
                 where g.Count() > 1
                 select new {Key= g.Key, Values = g.Skip(1)};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM