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 the methods used to render the views in mvc?

549


How route table has been created in asp.net mvc?

554


What is filters in web api?

509


What is poco proxy? : Entity framework

554


How do I install .net framework?

526






How to change the action name in ASP.Net MVC?

570


Explain .Net Framework? Why we use it?

609


What is the domain object?

541


Do you know about the new features in asp.net mvc 4 (asp.net mvc4)?

574


What are the versions of .net framework?

533


i just want to write an exam regarding .net?plz give me information about taking a test?where to pay 4 d exam,exam centre?

1808


Explain linq to entities? : Entity framework

542


Is .net core faster than .net framework?

549


What is partialview in asp.net mvc?

594


I have 2+ years of fake experience,actually i could not answer for project questions..?how can i answer please suggest me..?

2646