Spørgsmål vedr. GetHashCode i custom class
Jeg har et spørgsmål som jeg slet ikke kan finde ud af at gribe an. Er der nogle der kan hjælpe mig igang?Spørgsmål: Consider the custom C# reference type - described below - in
which the equals operator is overridden: Which of these requirements
should be true for GetHashCode when implementing it in the custom
class?
[code]public class something
{
private int a;
public something(int, newA)...
public override bool Equals(object obj)..
}[/code]
Mine svarmuligheder er:
1) There are no requirements. since GetHashCode is used only by value
types
2) If two different objects of the same type are considered equal using
their equals operator, their hash code must be identical. The opposite is
NOT required
3) If two different objects of the same type are considered equal using
their equals operator, their hash code must be identical. The opposite IS
required
Tak..