开发者

Find elements existing in both collections using LINQ

开发者 https://www.devze.com 2023-03-17 17:55 出处:网络
Say I have two collections int[] foo = { 1, 2, 3, 4 }; int[] bar = { 2, 4, 6, 8 }; Wha开发者_运维问答t would be the simplest way using linq to select values that exist in both collections?

Say I have two collections

int[] foo = { 1, 2, 3, 4 };
int[] bar = { 2, 4, 6, 8 };

Wha开发者_运维问答t would be the simplest way using linq to select values that exist in both collections?

i.e. a collection containing 2 and 4.


int[] result = foo.Intersect(bar).ToArray();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号