Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- (new Person() == null).Dump();
- }
- class Person : IEquatable<Person>
- {
- public static readonly IEqualityComparer<Person> Comparer = new PersonEqualityComparer();
- public bool Equals(Person other)
- {
- return Comparer.Equals(this, other);
- }
- public static bool operator ==(Person x, Person y) => x?.Equals(y) == true;
- public static bool operator !=(Person x, Person y) => !(x == y);
- }
- class PersonEqualityComparer : IEqualityComparer<Person>
- {
- public bool Equals(Person x, Person y)
- {
- if(x == null) return true; // Bum!
- //if (ReferenceEquals(x, null)) return true; // No bum!
- return false;
- }
- public int GetHashCode(Person obj)
- {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement