使用LINQ,从a List<int>,如何检索包含重复多次的条目及其值的列表?
我有一个List<CustomPoint> points;包含近百万个对象的东西.从这个列表中我想得到恰好发生两次的对象列表.最快的方法是什么?我也会对非Linq选项感兴趣,因为我可能也必须在C++中这样做.
public class CustomPoint
{
public double X { get; set; }
public double Y { get; set; }
public CustomPoint(double x, double y)
{
this.X = x;
this.Y = y;
}
}
public class PointComparer : IEqualityComparer<CustomPoint>
{
public bool Equals(CustomPoint x, CustomPoint y)
{
return ((x.X == y.X) && (y.Y == x.Y));
}
public int GetHashCode(CustomPoint obj)
{
int hash = 0;
hash ^= obj.X.GetHashCode();
hash ^= obj.Y.GetHashCode();
return hash;
}
}
Run Code Online (Sandbox Code Playgroud)
基于这个答案,我试过, …