Skip to content

Commit

Permalink
fix CompareTo() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Mar 10, 2024
1 parent dc231db commit 5487709
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Maui.DataGrid.Sample/Models/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ public class Streak : IComparable

public int CompareTo(object? obj)
{
var score = Result == Result.Won ? NumStreak : -NumStreak;
if (obj is Streak s)
{
var otherScore = s.Result == Result.Won ? s.NumStreak : -s.NumStreak;
return score - otherScore;
// First compare the Result
var resultComparison = Result.CompareTo(s.Result);
if (resultComparison != 0)
{
return resultComparison;
}

// If Result is the same, then compare the NumStreak
return NumStreak.CompareTo(s.NumStreak);
}

return score;
throw new ArgumentException("Object is not a Streak");
}

/// <inheritdoc/>
Expand Down

0 comments on commit 5487709

Please sign in to comment.