If an interface inherits IEquatable the implementing class can define the behavior of the Equals method. Is it possible to define the behavior of == operations?
public interface IFoo : IEquatable
{}
public class Foo : IFoo
{
// IEquatable.Equals
public bool Equals(IFoo other)
{
// Compare by value here...
}
}
To check that two IFoo references are equal by comparing their values:
IFoo X = new Foo();
IFoo Y = new Foo();
if (X.Equals(Y))
{
// Do something
}
Is it possible to make if (X == Y)
use the Equals method on Foo?