【问题标题】:Find elements existing in both collections using LINQ使用 LINQ 查找两个集合中存在的元素
【发布时间】:2023-04-02 00:47:02
【问题描述】:

假设我有两个系列

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

使用 linq 选择两个集合中都存在的值的最简单方法是什么?

即包含 2 和 4 的集合。

【问题讨论】:

    标签: c# .net linq intersection


    【解决方案1】:
    int[] result = foo.Intersect(bar).ToArray();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-30
      • 2013-01-17
      • 1970-01-01
      相关资源
      最近更新 更多