Click to See Complete Forum and Search --> : Need Help Understanding - IComparer Code


a358
March 26th, 2009, 06:37 PM
Hi,

I have the following function in a program that I am modifying. I know that its sorting a collection of Card classes by the Rank property.

But I don't understand the code, why are they multiplying the rank value by 100?



private class RankComparer : IComparer<Card> {
public int Compare(Card x, Card y) {
return (100 * (int)x.Rank + (int)x.Suit).CompareTo(100 * (int)y.Rank + (int)y.Suit);
}
}

boudino
March 27th, 2009, 02:48 AM
It shifts the value and condenses two values into just one. It is not neccessary, you can compare ranks and suites separatelly.