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

When would you set this property to false?

2 Answers  


Explain the features that make asp.net more used framework? : asp.net mvc

0 Answers  


Project Architecture (3tier, n-tier)

1 Answers   Syntel,


What is interval time of GC in .net

2 Answers  


What are the various ways of securing a web site that could prevent from hacking etc ?

1 Answers  






What is the roll of JIT in asp.net?

7 Answers  


What is session state server?

0 Answers  


Finally and dispose methods?

1 Answers   Microsoft,


what is page life cycle state management postback cross page postback types of feilds in gridview gridview events their life cycle cte in sql diff truncate and delete paging concepts in gridview diff bet gridview datalist and repeater what new operations in sql 2005 compared to earlier you get

1 Answers   e4e,


Difference between datareader and dataset ?

4 Answers   Microsoft,


Is asp.net easy to learn?

0 Answers  


State Management (viewstate, session etc)

2 Answers   Syntel,


Categories