Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find "not the same" elements in two arrays

Tags:

arrays

c#

list

I have two integer lists (List<int>). They contain the same elements, but List 1 contains elements that are not in the List 2.

How to find which elements of the List 1 ARE NOT in the List 2.

Thanks :)

PS. lang is c#

like image 945
trnTash Avatar asked Jun 01 '10 17:06

trnTash


2 Answers

You can use IEnumerable.Except:

list1.Except(list2);
like image 115
bruno conde Avatar answered Sep 24 '22 02:09

bruno conde


new HashSet<int>(l1).ExceptWith(l2);
like image 32
Matthew Flaschen Avatar answered Sep 22 '22 02:09

Matthew Flaschen