Static Modifier in c sharp

By using static  keyword we can define a class and its member static.

Member of class divided into two categories

  1. Instance member
  2. Static member
Members of a class which doesn’t required Instance of class neither for Initialization nor for execution, are known as Static members whereas  members of a class which requires the Instance of a class both for Initialization as well for execution also are known as Instance members.

Difference between Instance Variable and Static Variable 

  • If a variable is explicitly define by using static modifier or If a variable is  declare under static block we call those variable as static variable. Whereas rest of everything is Instance. 


                         
  • Static variables are Initialized Immediately once the execution of a class start, whereas Instance variable of a class are Initialized only after creating the Instance of the class and moreover each and every time Instance is created.
  • In the life cycle of class a static variable is initialized one and only one time where instance variable are initialized for zero times if no instance are created an n times if n instance are created.
  • The initialization of instance variable is associated with constructor calling so we get a chance of pass a new value to instance variable every time we create an instance, through the constructor.                                                                                                                                                                     

No comments:

Post a Comment