Re: Calling the base class constructor

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 05/26/04


Date: Wed, 26 May 2004 18:02:06 +0100

cody <no_spam_deutronium@gmx.net> wrote:
> > 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#.

Just having the Java syntax wouldn't allow that - Java doesn't allow
anything else to happen before the constructor is called either.

For parameter processing, the normal approach is to write a static
method which massages the parameters appropriately, and use

public Foo(int x) : base (Massage(x))
{
...
}

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too