Call base constructor to init member variables : Member Variable : Class C# Examples


C# Examples » Class » Member Variable »

 

Call base constructor to init member variables









    
public  class  A
{
      public  A(  int  x  )
      {
            this.x  =  x;
      }

      public  A()  :  this(  0  )
      {
      }

      internal  int  x;
}

public  class  B  :  A
{
      public  B()  :  base(  1  )
      {
      }

}

public  class  MainClass
{
      static  void  Main()
      {
            B  b  =  new  B();
            System.Console.WriteLine(  "A.x  =  {0}",  b.x  );
      }
}
    
   
  
   



Output

A.x = 1


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Member Variable