Create a gist now

Instantly share code, notes, and snippets.

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