c# list compare

蓝咒 提交于 2019-12-08 08:50:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!