C# difference between list of a class -
i got trouble getting difference between 2 list in c#.
how can difference ? have tried except did not result wanted.
for example: these products part of 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 quantity can change between old prd1 , new prd1
my problem when use var lsttodel = oldlst.except(newlst);
lsttodel filled oldlst , not make difference.
the desired result that
lsttodel = new list<product>(){prd1,prd3};
except accepts iequalitycomparer. create 1 in order determine products "equal", meaning have same properties. see more: https://msdn.microsoft.com/en-us/library/bb336390.aspx
Comments
Post a Comment