Wednesday, 13 March 2013

diference between constant and read-only in C#.net


Constant:
1.These can't be modified with in a class or out of the class.
2. Intializing constants at the time of declaration was mandatory.
3.Constant members behave as a static member,which can be acessed through class name.
4.Memory allocation can be taken only once.
Read Only:
1.These can't be modified out of a class,but can be modified with in a class.
2.Intializing these at the time of declaration is optional,they can be intialized through constructor.
3.These behave as instance members which can b accessed only through object.
4.Memory allocation of these gets performed separately for each object of the class.