How to intersect two different IEnumerable collections

前端 未结 4 676
遥遥无期
遥遥无期 2021-01-03 00:46

i think this question has been asked before but i havent been able to deduce a clear answer. I am trying to find the best way (or a way) to intersect two completely differen

4条回答
  •  半阙折子戏
    2021-01-03 01:38

    By using the intersect method, you can get common members between the two enumerables, like this example demonstrates:

    [Test]
    public void TestObjectIntersect()
    {
        var a = new List { 1, 2, 3, "test", "test2" };
        var b = new List { 4, 5, 1, "test2" };
        var c = a.Intersect(b);
        Console.WriteLine(String.Join(",", c.Select(x => x.ToString()).ToArray()));
    }
    
        

    提交回复
    热议问题