There should be a better way to do this, I'm sure ...
var a = new List<int>() { 1, 2, 3, 4, 5, 6 };
var b = new List<int>() { 2, 3, 5, 7, 11 };
var z = new List<int>();
for (int i = 0; i < a.Count; i++)
if (b.Contains(a[i]))
z.Add(a[i]);
I do not mind using the above technique, but I want something fast and efficient (I need to compare very large lists <> several times), and this is neither one nor the other! Any thoughts?
Edit: since it matters - I am using .NET 4.0, the original arrays are already sorted and do not contain duplicates.
Jocie source
share