Suppose there is a class A
class A:IComparable { int pole1; int pole2; public int CompareTo(A other) { return this.pole1.CompareTo(other.pole1); } }
And there is class B
class B<T> { T[] arr; public void Sort() { Array.Sort(arr); } }
Class B contains an array of objects of class A.
The question is, when I call the sorting of a class B object from Maine, they will all be sorted by the field pole1
. It is logical, because I pointed out that way.
How to make the sorting go according to the user's choice, i.e. sort by pole1
or pole2
.
I think so, you need to somehow indicate the sign, but I do not understand how to implement it. Tell me how to properly implement the method CompareTo()
and Sort()