First, actually implement IEquatable:
public struct Point: IEquatable<Point> {
public Point(int x, int y) {
this.X = x;
this.Y = y;
}
public int X { get; }
public int Y { get; }
public bool Equals (Point other) =>
this.X == other.X && this.Y == other.Y;
}
Then create a custom equality comparer. That requires an equality logic, and a hash code generator. For the equality logic, use SequenceEqual
, for the hash code generator, you'll have to play around with it, but here's an example via Jon Skeet. I used part of his logic below:
class ListPointComparer : IEqualityComparer<List<Point>> {
public bool Equals(List<Point> a, List<Point> b) => a.SequenceEqual(b);
public int GetHashCode(List<Point> list) {
int hash = 19;
foreach(var point in list)
hash = hash * 31 + point.GetHashCode();
return hash;
}
}
Now imagine points like this:
var pointsA = new List<Point> { new Point (1,1), new Point(2,2) };
var pointsB = new List<Point> { new Point (1,1), new Point(2,2) };
var pointsC = new List<Point> { new Point (3,3), new Point(4,4) };
var pointLists = new List<List<Point>> { pointsA, pointsB, pointsC };
Use your comparer class:
var results = pointLists.Distinct(new ListPointComparer());
// Outputs only 2 lists, with pointsA and pointsB combined.