/// <summary> /// Compares this instance to a specified <see cref="ScoreNamePair"/> instance. /// </summary> /// <param name="other">The other instance to compare to.</param> /// <returns>An indication of the two object's relative values.</returns> public int CompareTo(object other) { ScoreNamePair otherPair = (ScoreNamePair)other; if (this.Score == otherPair.Score) { return(this.Name.CompareTo(otherPair.Name)); } else { return(otherPair.Score.CompareTo(this.Score)); } }
/// <summary> /// Tries to add a score name pair to the table. /// </summary> /// <param name="scoreNamePair">The score name pair to add.</param> /// <returns>A value indicating whether the pair was added or not.</returns> public bool AddScore(ScoreNamePair scoreNamePair) { if (scoreNamePair.CompareTo(this.Scores[this.Scores.Count - 1]) < 0) { this.Scores.RemoveAt(this.Scores.Count - 1); this.Scores.Add(scoreNamePair); this.Scores.Sort(); return(true); } else { return(false); } }