11

Possible Duplicate:
Why can’t I create an abstract constructor on an abstract C# class?

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

Community
  • 1
  • 1
NileshChauhan
  • 5,469
  • 2
  • 29
  • 43

3 Answers3

19

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
  • 144,213
  • 56
  • 264
  • 302
18

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
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 6
    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 Jul 15 '10 at 08:59
  • 1
    http://msdn.microsoft.com/en-us/library/ms182126(v=vs.100).aspx -- sensible from the authoritative semantic viewpoint – nik.shornikov Apr 29 '12 at 18:42
2

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 Clarke
  • 17,511
  • 4
  • 41
  • 45