c# - Increase 1 to variable ,when we create an object -


hey i'm creating employed program tried make constructor share value wont create class called (employed ) inlcude instance variables : name string ; num int ; count int instanse 120 ; create proparaty set , name , proparaty count * every creating object increase 1 count

public class employed //creating class     { // creating instanse variable          private string name;         private  int number;         private static int count; //declare static can use in static method         public string proparaty         {             set             { name = value; }             { return name; }          }         public int propartyforcount         {                          {                 return count;             }         }        static employed() { // make static can share value             count = 120;            count++;          }      }     static void main(string[] args)     {         employed c1 = new employed();         employed c2 = new employed();         employed c3 = new employed();          console.write("the count number {0} ", c1.propartyforcount);     }  

static constructor executed once type (before first usage of type). msdn:

a static constructor called automatically initialize class before first instance created or static members referenced.

so, have count increased once.

if want increase variable each time when new employee instantiated, should in instance constructor:

private static int count = 120;  public employed()  {     count++; } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -