If I have:
public interface IValueStorage : IComparable<IValueStorage>
{
public int compareObject {get;}
public int CompareTo(IValueStorage other)
{
return compareObject.CompareTo(other.compareObject);
}
}
Why do I need to redefine the interface implementation of IComparable on any classes that implement this interface? Can I declare each member use the base implementation?
I would ordinarily just change this interface to an abstract class, but on this occasion, the implementers of this interface are all (and should remain) structs.
>Solution :
IService.CompareTo does not override IComparable<IService>.CompareTo; it creates a new method that your structs must implement. In order to have an interface method override another interface’s method, you must use the explicit interface implementation syntax:
public interface IService : IComparable<IService>
{
public int compareObject { get; }
int IComparable<IService>.CompareTo(IService other)
{
return compareObject.CompareTo(other.compareObject);
}
}