what is difference between const, static and readonly?

Answers were Sorted based on User's Feedback



what is difference between const, static and readonly?..

Answer / magesh

const variable : const can never be modified and
must be initialized to a compile time constant.

Static variable : you received last updated value, when u
getting value for static variable.

Readonly variable : The readonly variable can be changed
inside the constructor.

Is This Answer Correct ?    7 Yes 0 No

what is difference between const, static and readonly?..

Answer / amit manekar

The difference is that static read-only can be modified by
the containing class, but const can never be modified and
must be initialized to a compile time constant. To expand on
the static read-only case a bit, the containing class can
only modify it:

in the variable declaration (through a variable initializer).

in the static constructor (instance constructors if it's not
static).

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More ASP.NET Interview Questions

Why is it preferred to not use finalize for clean up?

0 Answers  


Explain how server control validation controls works?

2 Answers   CMS, Syntax Softtech,


What are sql notifications and sql invalidations?

0 Answers  


What are standard controls?

0 Answers  


What is the difference between HTTP-Post and HTTP-Get ?

1 Answers  






Why do we use datasource in asp.net?

0 Answers  


How does exception management works in ASP.NET?

0 Answers   Alcatel-Lucent,


What is variable and constant in .net programming language?

0 Answers  


What is boxing? How we can use it?

4 Answers   Infosys, NIIT,


Is it possible to prevent a browser from caching an ASPX page?

3 Answers  


How .Net has implemented security for web applications?

1 Answers  


What is difference cookie and session?

0 Answers  


Categories