Toán tử == so sánh theo tham chiếu đối với class (trừ khi bị override) nhưng so sánh theo giá trị với struct và kiểu nguyên thủy. Equals() mặc định so sánh theo giá trị.
- Với custom types, nên override cả hai để nhất quán.
- Để tuân thủ best practice, hãy implement cả
IEquatable<T>cùng với việc overrideGetHashCode().
The == operator compares references for classes (unless overloaded) but compares values for structs and primitives. Equals() compares values by default.
- Override both for custom types to keep them consistent.
- Best practice: also implement
IEquatable<T>and overrideGetHashCode().