... | ... | @@ -578,3 +578,24 @@ class Dog : Animal |
|
|
}
|
|
|
```
|
|
|
|
|
|
### Equals 재정의
|
|
|
```c#
|
|
|
public override bool Equals(object obj)
|
|
|
{
|
|
|
if(obj == null) //비교하려는 대상이 null인지 비교.
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
Animal animal = obj as Animal;
|
|
|
if(animal == null) //비교하려는 대상이 타입이 맞는지 비교.
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return this.key == animal.key; //비교하려는 대상의 키값이 일치하는지 비교.
|
|
|
}
|
|
|
```
|
|
|
|
|
|
### GetHashCode 재정의
|
|
|
GetHashCode는 해당 객체를 구별할 수 있는 key값을 반환하면 된다. |