Last active
June 11, 2016 22:55
-
-
Save JayBazuzi/8d025d68706998bf091445454a2e4c74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomerId | |
{ | |
public CustomerId(string value) | |
{ | |
this.Value = value; | |
} | |
public readonly string Value; | |
public override bool Equals(object obj) | |
{ | |
if (ReferenceEquals(null, obj)) return false; | |
if (obj.GetType() != GetType()) return false; | |
return string.Equals(this.Value, ((CustomerId)obj).Value, StringComparison.OrdinalIgnoreCase); | |
} | |
public override int GetHashCode() | |
{ | |
return this.Value.GetHashCode(); | |
} | |
} | |
new CustomerId("ABC") == new CustomerId("abc") // True; that's a good thing | |
new HashSet<CustomerId> | |
{ | |
new CustomerId("ABC") | |
}.Contains(new CustomerId("abc")); // False! Bad! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment