c# - Find and select specific changes between two object lists -


i have 2 lists of object t. each t has unique key "t.key"

list<t> list1; list<t> list2; 

i want create list of keys of objects in list2 ones in both lists have specific property differences (lets name them t.a , t.b). list contents not in same order.

example input/output:

list1 = {{key:1,a:10,b:10,c:10}, {key:2,a:10,b:10,c:10}, {key:3,a:10,b:10,c:10}} list2 = {{key:1,a:10,b:10,c:99}, {key:2,a:11,b:10,c:10}, {key:4,a:10,b:10,c:10}}  result = {2,4} 

this produces expected output:

 list<t> list1 = new list<t> { new t { key = 1, = 10, b = 10, c = 10 }, new t { key = 2, = 10, b = 10, c = 10 }, new t { key = 3, = 10, b = 10, c = 10 } };  list<t> list2 = new list<t> { new t { key = 1, = 10, b = 10, c = 99 }, new t { key = 2, = 11, b = 10, c = 10 }, new t { key = 4, = 10, b = 10, c = 10 } };   list<int> difference = new list<int>();   foreach (var item2 in list2)  {      var item1 = list1.firstordefault(i => i.key == item2.key);       if (item1 != null)      {          if (item2.a == item1.a && item2.b == item1.b)              continue;      }                  difference.add(item2.key);  } 

difference contains {2,4}


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -