Is there any way to manipulate variables passed in to a child class constructor before passing it of

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-04-20T05:41:37Z Indexed on 2010/04/20 5:43 UTC
Read the original article Hit count: 313

Hi,

Is there any way to delay calling a superclass constructor so you can manipulate the variables first?

Eg.

public class ParentClass
{
   private int someVar;

   public ParentClass(int someVar)
   {
       this.someVar = someVar;
   }
}

public class ChildClass : ParentClass
{
    public ChildClass(int someVar) : base(someVar)
    {
        someVar = someVar + 1
    }
}

I want to be able to send the new value for someVar (someVar + 1) to the base class constructor rather than the one passed in to the ChildClass constructor. Is there any way to do this?

Thanks,
Matt

© Stack Overflow or respective owner

Related posts about inheritance

Related posts about asp.net-mvc