Trying to get distinct values from two List<int> objects
- by Mario
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!