Is there a way to make derived classes override ToString()?

.net, c#, inheritance, interface, tostring

Solution

Not through an interface.

You'll need to use an abstract class for this.

-- Edit

You can just re-declare 'ToString' as abstract:

abstract class Foo
{
    public override abstract string ToString ();
}

Problem

(I'm working in .NET 4.0 beta, C#.) I have an interface, and all classes derived from this interface should implement custom `ToString()` logic. Is that enforceable? If so, how?

Original source

Related problems