title: How count number of objects created with a static class variable?
body: <p>I created 3 objects of a class and I want to display on the console how many objects I have created (using a static class variable) - How do I do this ?</p>
  
  <p>I put <code>public static int count = 0;</code> in the class I created but I couldn't get it to increment (<code>count++;</code>) based on how many objects I created of the class.  I created the 3 objects in the main method and gave them values for variables.</p>
  
  <p>here is the class I created in my program :</p>
  
  <pre><code>public class Student
          {
  
             public static int count = 0;
         //     count++;
  
  
              private string firstName;
  
              public string FirstName
  
              {           
                  get { return firstName; }
                  set { firstName = value; }
              }
  
  
              private string lastName;
  
              public string LastName
              {
                  get { return lastName; }
                  set { lastName = value; }
              }
              private string birthDate;
  
              public string BirthDate
              {
                  get { return birthDate; }
                  set { birthDate = value; }
              }
          }
  </code></pre>
  
  <p>In the main method I created 3 objects of class <code>Student</code>:</p>
  
  <pre><code>static void Main(string[] args)
          {
  
           //  Create 3 students    
              Student student1 = new Student       
              {
                  FirstName = "John",
                  LastName = "Wayne",
                  BirthDate = "26/05/1907"
  
              };
  
              Student student2 = new Student
              {
                  FirstName = "Craig",
                  LastName = "Playstead",
                  BirthDate ="01/01/1967"
              };
  
              Student student3 = new Student
              {
                  FirstName = "Paula",
                  LastName = "Smith",
                  BirthDate = "01/12/1977"
              };
  
  
              // Console.WriteLine("The course contains {1} students(s) " studentCounter );
  </code></pre>
  
  <p>I can't get the counter to ++ based on the way I created the objects.</p>