HashSets将提供最佳性能.您可以使用IntersectWith方法.
// assuming HashSet<T> hashSetA
// and an IEnumerable<T> collectionB
hashSetA.IntersectWith(collectionB);
Run Code Online (Sandbox Code Playgroud)
基于哈希集的解决方案提供的O(n)性能几乎与它一样好.
接下来最好的方法是对两个列表进行排序,然后在两个列表中以锁定步骤线性迭代,选择公共元素,这些元素具有O(nlogn)性能.