What is the difference b/w constant & read only variable?

Answer Posted / maloy.adhikari

Constants: The value can't be changed

Read-only: The value will be initialized only once from the
constructor of the class.


Const:
1)Can not be static.
2)The value is evaluated at compile time.
3)It is initialized at declaration only.
4)the const keyword is used for compile-time constants

Readonly:
1)Can be either instance-level or static.
2)The value is evaluated at run time.
3)It can be initialized in declaration or by code in the
constructor. Therefore, readonly fields can have different
values depending on the constructor used.
4)the readonly keyword is used for runtime constants.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is edm designer? : Entity framework

787


What are Action Methods in ASP.NET MVC?

863


What are the advantages of razor view engine?

730


What is entitytypes? : Entity framework

820


Explain covariance and contra-variance in .net framework 4.0. Give an example for each.

806


What is the .net framework and how does it work?

779


What are ajax helpers in mvc?

751


Can we have enum in entity framework?

847


What are the components required to create a route in mvc?

839


What are scaffold templates in mvc?

798


What is entity framework firstordefault?

763


What are actions in asp.net mvc?

842


How to enable Attribute Routing?

880


What is layout in mvc?

802


What is an asynchronous controller in asp.net mvc?

760