I have a list of lists:
List<Tuple<string, List<SomeObject>>
I want to select all SomeObjects
that exist in all rows of the list above.
Some will just exist in one or two lists, but I want all objects that exist in every single list, with other objects discarded.
I can't figure out an elegant solution to this without a bunch of c# code. Is there a nice way?
list.Select (x => x.Item2 as IEnumerable<SomeObject>)
.Aggregate((x,y)=> x.Intersect(y))
.ToList();
Or, as Jeppe Stig Nielsen suggested (and I think it's much more elegant):
list.Select(x => x.Item2.AsEnumerable())
.Aggregate(Enumerable.Intersect)
.ToList();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments