Trying to get distinct values from two List<int> objects
Posted
by Mario
on Stack Overflow
See other posts from Stack Overflow
or by Mario
Published on 2010-04-01T15:12:32Z
Indexed on
2010/04/01
15:13 UTC
Read the original article
Hit count: 252
I have 2 List objects:
List<int> lst1 = new List<int>();
List<int> lst2 = new List<int>();
Let's say they have values:
lst1.Add(1);
lst1.Add(2);
lst1.Add(3);
lst1.Add(4);
lst2.Add(1);
lst2.Add(4);
I need to get an object containing the "distinct" list of both of these; so in this case the return would be List {2, 3}.
Is there an easy way to do this? Or do I need to iterate through each value of the lists and compare?
I am open to using ObjectQuery, LINQ, etc as these lists are coming from a database, and could potentially be several hundred to several thousand entries long.
Thanks!
© Stack Overflow or respective owner