// To sort exercises, e.g. in the exercise list, sort them by exercise number public int CompareTo(Exercise other) { if (ChapterNo != other.ChapterNo) { throw new InvalidOperationException("Can only compare two exercises with each other if they are both in the same chapter"); } return(ExerciseNo.CompareTo(other.ExerciseNo)); }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + ChapterNo.GetHashCode(); hash = hash * 23 + ExerciseNo.GetHashCode(); return(hash); } }