Use this and base together to init a class : Member Variable : Class C# Examples


C# Examples » Class » Member Variable »

 

Use this and base together to init a class









    
using  System;

class  Base
{
      public  Base(  int  x  )
      {
            Console.WriteLine(  "Base.Base(int)"  );
            this.x  =  x;
      }
      
      public  int  x  =  0;
}

class  Derived  :  Base
{
      public  Derived(  int  a  ):base(  a  )
      {
            Console.WriteLine(  "Derived.Derived(int)"  );
            this.a  =  a;
      }

      public  Derived(  int  a,  int  b  ):this(  a  )
      {
            Console.WriteLine(  "Derived.Derived(int,  int)"  );
            this.a  =  a;
            this.b  =  b;
      }

      public  int  a  =  0;
      public  int  b  =  0;
}

public  class  MainClass
{
      static  void  Main()
      {
            Derived  b  =  new  Derived(  1,  2  );
      }
}
    
   
  
   



Output

Base.Base(int)
Derived.Derived(int)
Derived.Derived(int, int)


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Member Variable