|
-
March 26th, 2009, 06:37 PM
#1
Need Help Understanding - IComparer Code
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?
Code:
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);
}
}
-
March 27th, 2009, 02:48 AM
#2
Re: Need Help Understanding - IComparer Code
It shifts the value and condenses two values into just one. It is not neccessary, you can compare ranks and suites separatelly.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|