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
How we can call a javascript function on the change of a dropdown list in mvc?
How you can implement custom validation in asp.net MVC?
What is oauth in web api?
Will there be a .net compact framework 3.0 release with release of .net framework 3.0?
Which version of .net framework is installed?
What is the use of viewmodel in mvc?
What is the difference between model and entity?
What are the main features of asp.net mvc 4 used by asp.net web api?
Give an example for authorization filters in an asp.net mvc application?
What is the .net framework?
What does a viewmodel do?
How to Redirect Tracing to a File
How do I install .net framework?
Explain the types of Scaffoldings.
What is .net framework used for?