Home > Software > .NET > Dot-Net
Interview Questions   Tutorials   Discussions   

Dot-Net - What is the difference between constant & read only variable?




252
views
asked mar October 4, 2014 06:15 AM  

What is the difference between constant & read only variable?


           

1 Answers



 
answered By siddhant   0  

Constants

  • Constants are static by default
  • They must have a value at compilation-time (you can have e.g. 3.14 * 2, but cannot call methods)
  • Could be declared within functions
  • Are copied into every assembly that uses them (every assembly gets a local copy of values)
  • Can be used in attributes

Readonly instance fields

  • Must have set value, by the time constructor exits
  • Are evaluated when instance is created
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert