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


Please Help Members By Posting Answers For Below Questions

What is better C# or VB.NET?

681


What is CLR and its application.?

748


Explain the ways to deploy an assembly?

709


If I have more than one version of one assemblies, then how'll I use old version (how/where to specify version number?)in my application?

698


What is the difference between abstract and virtual?

659


Does the variables of a private class-level inherited?

761


What is the difference between static class and singleton class in c#?

674


What is the predicate of a sentence?

651


What is overloading with example?

699


Can we overload indexer in c#?

665


what is IEquatable

737


How do I make a dll in c#?

694


How to sort an int array in c#?

725


What is dataview c#?

621


Explain About web methods and its various attributes

744