Yes, it is required to implement overloads for both == and != if you implement one of them.
There's a very standard way of doing this, and you should also implement an over-ride for the .Equals method:
public class SomeClass
{
public string ClassName { set; get; }
public SomeClass(string name)
{
ClassName = name;
}
protected bool Equals(SomeClass other)
{
return string.Equals(ClassName, other.ClassName);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((SomeClass)obj);
}
public override int GetHashCode()
{
return (ClassName != null ? ClassName.GetHashCode() : 0);
}
public static bool operator ==(SomeClass c1, SomeClass c2)
{
return c1.ClassName == c2.ClassName;
}
public static bool operator !=(SomeClass c1, SomeClass c2)
{
return !(c1 == c2);
}
}