Skip to content

Instantly share code, notes, and snippets.

@wickedshimmy
Created August 7, 2011 19:16
Show Gist options
  • Save wickedshimmy/1130676 to your computer and use it in GitHub Desktop.
Save wickedshimmy/1130676 to your computer and use it in GitHub Desktop.
class T : IEquatable<T> {
public sealed override int GetHashCode ()
{
return 4; // guaranteed to be random
}
public sealed override bool Equals (object o)
{
var t = o as T;
return t != null && Equals (t);
}
public bool Equals (T other)
{
if (Object.ReferenceEquals (other, null))
return false;
if (Object.ReferenceEquals (this, other))
return true;
return true; // real equality logic
}
public static bool operator == (T x, T y)
{
if (Object.ReferenceEquals (x, null))
return Object.ReferenceEquals (y, null);
return x.Equals (y);
}
public static bool operator != (T x, T y)
{
return !(x == y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment