T
Tony
Hello!
Here I have a Card class with several methods.
Now to my question I don't really fully understand what purpose this
GetHashCode is used for.
That's why I bring it up again.
In this simple example below with the Card class what would happen if I skip
this GetHashCode in this Card class?
Is it possible to write some simple test program to prove that this
GetHashCode will prevent
error or problem to occur?
class Card
{
//rank and suit are defined here
public static bool operator==(Card card1, Card card2)
{
return card1.suit == card2.suit) && (card1.rank==card2.rank);
}
public override bool Equals(object card)
{
return this == (Card) card;
}
public override int HetHashCode()
{
return 13*(int)rank + (int)suit;
}
....
....
}
//Tony
Here I have a Card class with several methods.
Now to my question I don't really fully understand what purpose this
GetHashCode is used for.
That's why I bring it up again.
In this simple example below with the Card class what would happen if I skip
this GetHashCode in this Card class?
Is it possible to write some simple test program to prove that this
GetHashCode will prevent
error or problem to occur?
class Card
{
//rank and suit are defined here
public static bool operator==(Card card1, Card card2)
{
return card1.suit == card2.suit) && (card1.rank==card2.rank);
}
public override bool Equals(object card)
{
return this == (Card) card;
}
public override int HetHashCode()
{
return 13*(int)rank + (int)suit;
}
....
....
}
//Tony