【问题标题】:Intersect two arrays相交两个数组
【发布时间】:2010-11-22 17:43:41
【问题描述】:

如何在 C# 中快速找到两个数组之间的交集?

【问题讨论】:

    标签: arrays c#-4.0 intersection


    【解决方案1】:

    在 Enumerable 上有 Intersect 扩展方法。它适用于任何IEnumerable<T>,包括数组。

    【讨论】:

      【解决方案2】:

      这是一个使用 Linq Intersect 的示例。

      // Assign two arrays.
      int[] array1 = { 1, 2, 4 };
      int[] array2 = { 2, 3, 4 };
      
      // Call Intersect extension method.
      var intersect = array1.Intersect(array2);
      
      foreach (int value in intersect)
      {
          label1.Text += value + "\n";
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-08
        • 2018-09-02
        • 2017-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-31
        • 2012-08-23
        相关资源
        最近更新 更多