compare two list and return not matching items using linq

后端 未结 10 574
死守一世寂寞
死守一世寂寞 2021-02-01 02:52

i have a two list

List SentList;
List MsgList;

both have the same property called MsgID;

MsgList            


        
10条回答
  •  时光取名叫无心
    2021-02-01 03:08

    List cars = new List() {  new Car() { Name = "Ford", Year = 1892, Website = "www.ford.us" }, 
                                        new Car() { Name = "Jaguar", Year = 1892, Website = "www.jaguar.co.uk" }, 
                                        new Car() { Name = "Honda", Year = 1892, Website = "www.honda.jp"} };
    
    List factories = new List() {     new Factory() { Name = "Ferrari", Website = "www.ferrari.it" }, 
                                                        new Factory() { Name = "Jaguar", Website = "www.jaguar.co.uk" }, 
                                                        new Factory() { Name = "BMW", Website = "www.bmw.de"} };
    
    foreach (Car car in cars.Where(c => !factories.Any(f => f.Name == c.Name))) {
        lblDebug.Text += car.Name;
    }
    

提交回复
热议问题