Reference a static member variable without using the class name : static field « Class « C# / CSharp Tutorial






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 );

   }
}
Static Field Employee.totalHeadCount is 456








7.44.static field
7.44.1.Static Fields
7.44.2.Use a static field to count instances.
7.44.3.Use a static constructor.
7.44.4.Reference Static Field without Instance
7.44.5.Static field init
7.44.6.Reference a static member variable without using the class name
7.44.7.Instance Counting