Static field init : Static field : Class C# Examples


C# Examples » Class » Static field »

 

Static field init









    
using  System;

public  class  MyClass
{
      private  static  int  InitX()
      {
            Console.WriteLine(  "MyClass.InitX()"  );
            return  1;
      }
      private  static  int  InitY()
      {
            Console.WriteLine(  "MyClass.InitY()"  );
            return  2;
      }
      private  static  int  InitA()
      {
            Console.WriteLine(  "MyClass.InitA()"  );
            return  3;
      }
      private  static  int  InitB()
      {
            Console.WriteLine(  "MyClass.InitB()"  );
            return  4;
      }

      private  int  y  =  InitY();
      private  int  x  =  InitX();

      private  static  int  a  =  InitA();
      private  static  int  b  =  InitB();
}

public  class  MainClass
{
      static  void  Main()
      {
            MyClass  a  =  new  MyClass();
      }
}
    
   
  
   



Output

MyClass.InitA()
MyClass.InitB()
MyClass.InitY()
MyClass.InitX()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Static field