views:

238

answers:

4

My test code in C#:

namespace DSnA
{
    public abstract class Test : IComparable
    {

    }
}

Results in the following compiler error:

error CS0535: 'DSnA.Test' does not implement interface member
'System.IComparable.CompareTo(object)'

Since the class Test is an abstract class, why does the compiler require it to implement the interface? Shouldn't this requirement only be compulsory for concrete classes?

+5  A: 

you can just put the definition of method and mark abstract

Andrey
+9  A: 

In C# you still define the methods, but you don't provide a body and you mark it as abstract. Like so:

interface IFoo
{
    void Bar();
}

abstract class Foo : IFoo
{
    public abstract void Bar();
}
Joel
A: 

They don't have to actually implement the interface.
The interface methods/properties can be abstract or even virtual as well. So its up to the subclasses to actually implement them.

ntziolis