Home > Software > .NET > C-Sharp
Interview Questions   Tutorials   Discussions   

C-Sharp - What is the Difference between read only and constant variables?




283
views
asked mar October 4, 2014 03:22 AM  

What is the Difference between read only and constant variables?


           

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