You have implemented both IComparable
and Icomparable<T>
.
So you have to implement both CompareTo
methods.
public int CompareTo(object obj) // implement method from IComaparable<T> interface
{
return CompareStudent(this, (Student)obj);
}
public int CompareTo(Student obj) // implement method from IComaparable interface
{
if (obj != null && !(obj is Student))
throw new ArgumentException("Object must be of type Student.");
return CompareStudent(this, obj);
}
public int CompareStudent(Student st1, Student st2)
{
// You can change it as you want
// I am comparing their ages
return st1.age.CompareTo(st2.age);
}