tags:

views:

88

answers:

4

Can abstract class's Constructor be marked as 'abstract'?

+5  A: 

No. C# does not support this in any version. Note that constructors are not inherited in derived classes, although they can be "chained". This is probably what you want to be doing.

If you want to indicate that the derived class should be doing some sort of initialisation, you could create an abstract Initialise method or such which the constructor of the base class (and indirectly of the sub-class) calls on creation.

As a side point, I'm not sure whether the CLR (or associated CIL language) actually supports it - I would suspect it may, though there is little use for it from within C# for the reason just mentioned.

Noldorin
+9  A: 

No, a constructor cannot be marked as abstract. In abstract classes constructors are usually marked as protected though, at least that's what I would recommend you doing.

Darin Dimitrov
It actually doesn't matter whether you mark them as `protected` or the normal `public`, since they are only accessible via chaining in derived classes anyway! Saying that, marking as `protected` is probably sensible from a semantic viewpoint.
Noldorin
+1  A: 

No, because you don't override constructors in C#. Declaring a constructor abstract means subclasses have to override it, which isn't possible.

BoltClock
+1  A: 

Basically no.

If its abstract, you have to override it in a concrete child class, and you can't override a constructor, only overload it.

Russ C