获取2个集合List<T>的共同元素,循环2个集合,然后比对。

获取2个集合List<T>的共同元素

 

class Bj
    {
        public void GetIntersect()
        {
            var listA = new List<int> { 2, 5, 6, 8, 23, 56, 4 };
            var listB = new List<int> { 1, 6, 9, 11, 34, 29, 5, 23, 4 };

            foreach (int a in listA)
            {
                foreach (int b in listB)
                {
                    if (a == b)
                    {
                        Console.WriteLine(a);
                    }
                }
            }
        }
    }
Source Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
相关资源
相似解决方案