I haven't implemented any but the implementation can be a bit tricky for the case 1 & 2.1
Case 1 & 2.1
Implement IComparable interface for instance of the class you are comparing.
So that you can compare current & next objects in an array.
Also override the comparison operators (>, >=, <, <=).
// To enable Point class object instance comparable.publicclassPoint:IComparable<Point>{publicintCompareTo(PointotherPoint){returnthis.X>otherPoint.X&&this.Y>otherPoint.Y;}publicstaticbooloperator>(Pointp1,Pointp2)=>p1.CompareTo(p2)==1;publicstaticbooloperator<(Pointp1,Pointp2)=>p1.CompareTo(p2)==-1;publicstaticbooloperator>=(Pointp1,Pointp2)=>p1.CompareTo(p2)>=0;publicstaticbooloperator<=(Pointp1,Pointp2)p1.CompareTo(p2)<=0;}...// case 1if(a[i]!=a[i+1]){result.Add(a[i]);}// case 2.1if(!alreadySeen.Contains(item))alreadySeen.Add(item);
For Case 2.2
Create a class implementing IComparer interface so that you can specify how objects can be sorted.
I haven't implemented any but the implementation can be a bit tricky for the case 1 & 2.1
Case 1 & 2.1
operators
(>, >=, <, <=).For Case 2.2
Create a class implementing IComparer interface so that you can specify how objects can be sorted.