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 form feed in c#?

733


Name some properties of thread class.

758


What is dll hell, and how does .net solve it?

713


What is a generic class?

703


What are the advantages of constructor?

614


What is an icollection in c#?

663


Explain About web methods and its various attributes

742


What is the best dependency injection c#?

657


Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?

695


Okay, so an int is a value type, and a class is a reference type. How can int be derived from object?

742


What is managed code?

718


What is the difference between ref and out parameters in c#?

679


How can I check the type of an object at runtime?

718


How do you achieve polymorphism in c#?

662


1. Describe page life cycle?

1813