I got trouble getting the difference between 2 list in c#.
How can i get the difference ? I have tried Except but I did not get the result i wanted.
for example: These products are part of a bill
class Product {
public int id_prod;
public int quantity;
public float price;
}
Product prd1 = new Product(){1,2,34};
Product prd2 = new Product(){2,5,20};
Product prd3 = new Product(){3,6,14};
Product prd4 = new Product(){4,9,8};
Product prd5 = new Product(){5,12,70};
Product prd1b = new Product(){1,60,34};
List<Product> oldLst = new List<Product>(){ prd1,prd2,prd3};
List<Product> newLst = new List<Product>(){ prd1b,prd2,prd4,prd5};
Note that the quantity can change between the old prd1 and the new prd1
My problem is when i use var lstToDel = oldLst.Except(newLst);
lstToDel is filled with oldLst and does not make the difference.
The desired result would be that
lstToDel = new List<Product>(){prd1,prd3};