Uzyskaj różne i wspólne elementy w dwóch tablicach za pomocą LINQ [closed]
Na przykład mam dwie tablice:
var list1 = string[] {"1", "2", "3", "4", "5", "6"};
var list2 = string[] {"2", "3", "4"};
Próbuję to zrobić -
Uzyskaj typowe przedmioty zlist1
ilist2
(np. {"2", "3", "4"})Zdobądź różne przedmiotylist1
ilist2
(np. {"1", "5", "6"})Próbowałem więc z LINQ i -
var listDiff = list1.Except(list2); //This gets the desire result for different items
Ale,
var listCommon = list1.Intersect(list2); //This doesn't give me desire result. Comes out as {"1", "5", "6", "2", "3", "4"};
Jakieś pomysły?