Creating and Killing an instance in c sharp

Creating an instance of a class



  • Every member ( here in above example variable x) of a class if it is non-static can access from the main method only by using Instance of the class(p is the instance of a class Program).
  • A variable of a class is a Copy of class that is not Initialized whereas the Instance of the class is  copy of a class that is Initialized by using new keyword.



How to kill Instance of a class ?

  • we can kill the Instance of a class by assigning null to it and once null is assigned to an Instance the Instance cannot access the Object memory that is allocated to it and Object memory is marked as unused. After assigning null to an instance we cannot call any member using that instance because the Instance is again treated like a variable of a class.


















No comments:

Post a Comment