Re: Calling the base class constructor

From: cody (no_spam_deutronium_at_gmx.net)
Date: 05/26/04


Date: Wed, 26 May 2004 15:15:58 +0200


> > I was wondering how I could call the base class constructor from a
derived
> > class constructor. In Java I could do something like
> >
> > super(parameter);
> >
> > I tried
> >
> > base(parameter);
> >
> > in C# but it doesn't compile. Any ideas?
>
> You do base (parameter) but in a different place:
>
> public Derived() : base (...)
> {
> }
>
> See http://www.pobox.com/~skeet/csharp/constructors.html for more
> information.

I've never understood why this special syntax is used here. Why not do it
like java and allow base(param);?
This would give you the freedom to do parameter processing before calling
the base ctor or you could do a try{}catch around the base()-call in future
versions of c#.

--
cody
Freeware Tools, Games and Humour
http://www.deutronium.de.vu  || http://www.deutronium.tk


Relevant Pages

  • C# Constructors
    ... I am very new to C# but have worked with Java for ... documentation is how to call the superclass/based on class constructor ... it the base class properties are not used. ... in the InitializeComponent method or would it go in the Constructor? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Calling the base class constructor
    ... > I was wondering how I could call the base class constructor from a derived ... In Java I could do something like ... > in C# but it doesn't compile. ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.languages.csharp)
  • Calling the base class constructor
    ... I was wondering how I could call the base class constructor from a derived ... In Java I could do something like ... Student Computer Science at the tUL ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Calling the base class constructor
    ... > I've never understood why this special syntax is used here. ... > the base ctor or you could do a trycatch around the base-call in future ... Just having the Java syntax wouldn't allow that - Java doesn't allow ... For parameter processing, the normal approach is to write a static ...
    (microsoft.public.dotnet.languages.csharp)