What is the Difference between read only and constant
variables?
Answer Posted / bharathi
Constants:
constant is used for declaring variable as constant and this constant value cannot be modified once after declartration.
It is must to declare the constant value at the time of declaration only.
Example:
constant int y=5;
Readonly
Readonly variables can not be modified like constant,but it is after initialization.
So.it is not mandatory to initialize those variables at declaration time.they can also be initialize after declaration.
Example:
readonly int x;
add()
{
x=5;
}
Both after initilization, we can not modify those values again.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why constructor is used in c#?
What is the difference between func and action delegate?
Is datetime value type c#?
How do I simulate optional parameters to com calls?
What is the difference between a function and a method?
What is multicast delegate explain with example?
Value Type and Reference Type Data type in C#?
Why do we Need of static class in c#?
What is this keyword in C#?
What is singleordefault?
Why do canadians say zed?
How do I port "synchronized" functions from visual j++ to c#?
What does the initial catalog parameter define in the connection string?
What are the extension methods in c#?
What is difference between function and method in c#?