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 does int parse do in c#?

471


How many constructors can a class have in c#?

481


why delegate is type safe?

2603


What is string in c# net?

496


Give examples for value types?

489






What is generic delegate in c#?

460


What is ado c#?

535


What is the difference between overriding and overloading in systemverilog?

457


How many types of collections are there in c#?

482


In dynamic link library, which api is used for load library?

523


Can derived classes have greater accessibility than their base types?

539


Is stringbuilder faster than string concatenation c#?

446


Why we use get and set property in c#?

517


Why abstract class is not instantiated in c#?

525


Is friend a constructor?

510