venus najad

venus najad

  • 1k
  • 414
  • 29.2k

How to sort a list with multiple parameters using CompareTo

Feb 19 2019 9:43 AM
hello... i have made a list of students, which contains name, age, grade and an annotation...
some of students has same name or some has same grade or some has same age...
 
when i run the program, it complains that the object is already exits...
my CompareTo method is as follow
 
public int CompareTo(Student other)
{
// If other is not a student
if (other == null)
{
throw new NotImplementedException();
throw new ArgumentException("Other is not a student");
}
// The comparison depends on the comparison of
// the underlying grade, age or name.
else if (this._name.CompareTo(other._name) > 1)
return other.OrderBy(s => s._name).ThenBy(s => s._age);
//return this._age.CompareTo(other._age);
else
return this._name.CompareTo(other._name);
}
 
it doesnt recognize OrderBy... 
 i appreciate any help... regards 
 
 

Answers (2)