A
AMP
Hello,
I am using the Head First book to try and understand interfaces.There
is one thing I dont understand about the following code:
public void Sort()
{
cards.Sort(new CardComparer_bySuit());
}
Calls the function Compare()
in this class:
namespace __Two_Decks
{
class CardComparer_bySuit : IComparer<Card>
{
public int Compare(Card x, Card y)
{
if (x.Suit > y.Suit)
return 1;
if (x.Suit < y.Suit)
return -1;
if (x.Value > y.Value)
return 1;
if (x.Value < y.Value)
return -1;
return 0;
}
}
}
I understand the that the class has to implement Compare(), but what
if there were 2 methods that ICompared had signatures for. As I said,
the function (cards.Sort()) calls the class, not the method
Compare().
I dont get it.
Thanks
Mike
The code is on the Oreilly site.
I am using the Head First book to try and understand interfaces.There
is one thing I dont understand about the following code:
public void Sort()
{
cards.Sort(new CardComparer_bySuit());
}
Calls the function Compare()
in this class:
namespace __Two_Decks
{
class CardComparer_bySuit : IComparer<Card>
{
public int Compare(Card x, Card y)
{
if (x.Suit > y.Suit)
return 1;
if (x.Suit < y.Suit)
return -1;
if (x.Value > y.Value)
return 1;
if (x.Value < y.Value)
return -1;
return 0;
}
}
}
I understand the that the class has to implement Compare(), but what
if there were 2 methods that ICompared had signatures for. As I said,
the function (cards.Sort()) calls the class, not the method
Compare().
I dont get it.
Thanks
Mike
The code is on the Oreilly site.