Last active
May 5, 2018 21:19
-
-
Save canton7/72abf244ad5e3f623f71 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class Foo : IEquatable<Foo> | |
{ | |
public int Bar { get; set; } | |
public int Baz { get; set; } | |
public override bool Equals(object obj) | |
{ | |
return this.Equals(obj as Foo); | |
} | |
public bool Equals(Foo other) | |
{ | |
if (Object.ReferenceEquals(other, null)) | |
return false; | |
if (Object.ReferenceEquals(this, other)) | |
return true; | |
return this.Bar.Equals(other.Bar) && | |
this.Baz.Equals(other.Baz); | |
} | |
public override int GetHashCode() | |
{ | |
unchecked | |
{ | |
int hash = 17; | |
hash = hash * 23 + this.Bar.GetHashCode(); | |
hash = hash * 23 + this.Baz.GetHashCode(); | |
return hash; | |
} | |
} | |
} |
This file contains hidden or 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
public struct Foo : IEquatable<Foo> | |
{ | |
public int Bar { get; set; } | |
public int Baz { get; set; } | |
public override bool Equals(object obj) | |
{ | |
return (obj is Foo) && this.Equals((Foo)obj); | |
} | |
public bool Equals(Foo other) | |
{ | |
return this.Bar.Equals(other.Bar) && | |
this.Baz.Equals(other.Baz); | |
} | |
public override int GetHashCode() | |
{ | |
unchecked | |
{ | |
int hash = 17; | |
hash = hash * 23 + this.Bar.GetHashCode(); | |
hash = hash * 23 + this.Baz.GetHashCode(); | |
return hash; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment