What is the difference between readonly and const
Answers were Sorted based on User's Feedback
Answer / sabina
both meant for constant values. a const field can only be
initialized at the declaretion of the field. a read only
field can be initialized either in initialization or in
constructer. therefore , reaadonly field can have different
values depending on the constructure used
also a const field is compile time constant , readonly
field can be used for runtime constants
| Is This Answer Correct ? | 18 Yes | 2 No |
Answer / chandan kumar
The read only keyword is different from the const keyword. A
const field can only be initialized at the declaration of
the field. A read only field can be initialized either at
the declaration or in a constructor. Therefore, read only
fields can have different values depending on the
constructor used. Also, while a const field is a
compile-time constant, the read only field can be used for
runtime constants as in the
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / vishnu
a read only
field can be initialized either in initialization or in
constructor
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / porchelvi.a
Constant:
--------
we have to initialize at the declaration itself
we could not change the value of constant variable.
Read only:
----------
we can not initialize the Read only variable during
declaration.we can initialize it in constructor only.after
that we could not change the value.Read noly is instance
based variable.
| Is This Answer Correct ? | 1 Yes | 3 No |
What are circular references? How garbage collection deals with circular references.
Is it not possible to store a boolean value as a variable?
Define MSIL, and how does it works? Why our developers need an appreciation of it if at all?
What is the use of 'as' Keyword in C# ?
How does bitwise work?
What do you understand by 'access specifiers' in C#?
What is the use of ispostback in c#?
What is a generic method?
What is the use of static members with example using c#.net.
What is dll in vb.net?
List the 5 different access modifiers in c#?
What are the different types of assemblies available and their purpose?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)