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

explain why t4 entity is important in entity framework?

787


how do you truncate a table using entity data model?

850


Explain the difference between Viewbag and Viewdata in ASP.NET MVC?

792


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

793


What are the components of the .net framework.

785


what is more complex to implement property, methods or event? how can I define criteria to compare the difficulty of implementation between them? for example the number of methods wanted to implements property is 2 methods. how many methods I need it to implements events?

1971


mention in what all scenarios entity framework can be applicable?

1181


If I have multiple filters implemented, what is the order in which these filters get executed?

736


How can we determine action invoked from HTTP GET or HTTP POST?

789


Explain RenderBody and RenderPage in ASP.Net MVC?

815


What are Validation Annotations?

789


What is difference between razor and web form engine?

784


Explain what is the difference between view and partial view?

826


What is associationset? : Entity framework

809


what is split entity?

815