Hey there,

I have a class derived from another with a variable that is defined in the derived class but not in the base class.

I can set this variable in the constructor of the derived class but then it just defaults to 0 when trying to use it in an overridden function in the derived class.

Example:

Code:
public class A {

      protected int m_X;

      public A(int x) {
           m_X = x;
      }

      protected virtual int SomeFunction() {
           return m_X;
      }
}

public class B : A {
     private int m_Y;

     public B(int x, int y) : base(x) {
        m_Y = y;
     }

     protected override int SomeFunction()  {
         return m_Y;
     }
}


B myB = new B(1, 5);
myB.SomeFunction(); //returns 0 instead of 5
I'm sure its something silly. Can anyone help me out?

Thanks,
Lang