public int CompareTo(object obj) { int compareResult = 0; PokerHand otherHand = (PokerHand)obj; int thisValue = this.CalculateValue(); int otherValue = otherHand.CalculateValue(); if (thisValue == otherValue) { int index = 0; while (compareResult == 0 && index < 5) { compareResult = this.cards[index].Value - otherHand.cards[index].Value; index++; } } else { compareResult = thisValue - otherValue; } return(compareResult); }