What is the Difference between read only and constant
variables?

Answer Posted / akshay

Constants :

* Constant value. Cannot be changed once initialized.
Should be Initialize the value where it declared.
* Const value fully evaluated at compile time
* By default static
* Possible to declare within function

Readonly :

* Could be declare as Static or Non Static
* Assign the value where it declared or can be assigned in
constructor
* Could not declare within function
* can be initialized in compile time or in runtime.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is disco?

514


What are satellite assemblies?

554


What are the types of assembly available

499


How do I create a multilanguage?

510


What is the delegate in c#?

487






What do you mean by default constructor?

605


What is the relation between classes and objects?

520


Are c# strings immutable?

484


How does the clr work?

495


What is a .aspx file?

458


Is it possible to force garbage collector to run?

480


What is gridview c#?

497


Is c# 8 released?

482


Do events have return type c#?

502


Why do we need static in c#?

505