from a list, which got 3 attributes I want to return a new list of that class where attribut1 recurrence in the list equals X
for an example this;
1,a,b
1,c,d
1,e,f
2,a,b
2,c,d
3,a,b
3,c,d
3,e,f
4,a,b
5,a,b
5,c,d
5,e,f
6,a,b
6,e,f
where X = 1 would return that list
4,a,b
where X = 2 would return that list
2,a,b
2,c,d
6,a,b
6,e,f
where X = 3 would return that list
1,a,b
1,c,d
1,e,f
3,a,b
3,c,d
3,e,f
5,a,b
5,c,d
5,e,f
Perfect case for grouping!
var groups = list.GroupBy(s => s.Attribute1);
var recur_1 = groups.Where(g => g.Count() == 1).SelectMany(s => s);
var recur_2 = groups.Where(g => g.Count() == 2).SelectMany(s => s);
var recur_3 = groups.Where(g => g.Count() == 3).SelectMany(s => s);
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