Compare the difference between two list

后端 未结 3 1356
粉色の甜心
粉色の甜心 2020-12-10 02:15

I\'am trying to check the difference between two List in c#.

Example:

List FirstList = new List         


        
3条回答
  •  囚心锁ツ
    2020-12-10 03:14

    Try to use Except LINQ extension method, which takes items only from the first list, that are not present in the second. Example is given below:

    List ThirdList =  SecondList.Except(FirstList).ToList();
    

    You can print the result using the following code:

    Console.WriteLine(string.Join(Environment.NewLine, ThirdList));
    

    Or

    Debug.WriteLine(string.Join(Environment.NewLine, ThirdList));
    

    Note: Don't forget to include: using System.Diagnostics;

    prints:

    COM3
    

提交回复
热议问题