Reference a static member variable without using the class name : Static field : Class C# Examples


C# Examples » Class » Static field »

 

Reference a static member variable without using the class name









    
public  class  Employee
{
      public  Employee()
      {
            totalHeadCount  =  123;
            Employee.totalHeadCount  =  456;
      }

      public  static  int  totalHeadCount;
}

public  class  MainClass
{
      static  void  Main()
      {
            Employee  bob  =  new  Employee();
            
            System.Console.WriteLine("Static  Field  Employee.totalHeadCount  is  {0}",Employee.totalHeadCount  );

      }
}
    
   
  
   



Output

Static Field Employee.totalHeadCount is 456


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Static field