CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Location
    U.S.A
    Posts
    5

    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);
        }
    }

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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
  •  





Click Here to Expand Forum to Full Width

Featured