Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Wednesday, August 28, 2013

C# - What is the Difference between Const and Readonly

Const:

  •       Const can only be initialized at the time of declaration of the field.
  •       Const values will evaluate at compile time only.
  •      Const value can’t be changed these will be same at all the time.
  •      This type of fields are required when one of the field values remains constant throughout the system like Pi will remain same in your Maths Class.


Read-only:

  •     The value will be initialized either declaration time or the constructor of the class allowing you to pass the value at run time.
  •     Read only values will evaluate at runtime only.

No comments:

Post a Comment