问题
Hi I need to find a way to compare many (c#) List objects to output what numbers occur in each one.
E.g.
List1{1, 2, 3, 4, 5}
List2{1, 3, 6, 8}
List3{1, 2, 3}
this would return {1, 3}
回答1:
Use the Linq extension method Intersect.
var result = List1.Intersect(List2).Intersect(List3);
回答2:
LINQ intersect is built for that.
来源:https://stackoverflow.com/questions/5106788/c-sharp-list-compare