Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Last active June 11, 2016 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayBazuzi/8d025d68706998bf091445454a2e4c74 to your computer and use it in GitHub Desktop.
Save JayBazuzi/8d025d68706998bf091445454a2e4c74 to your computer and use it in GitHub Desktop.
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