What are the differences between const and readonly keywords ?

 Posted by Bharathi Cherukuri on 6/5/2012 | Category: ASP.NET Interview questions | Views: 2053 | Points: 40
Answer:

The major differences between both the keywords are listed below:

'const':
-cannot be static
-value is evaluated at compile time
-initialized at compile time only

'readonly':
-can't be either instance level or static
-value is evaluated at compile time
-can be initialized in declaration or by code in the constructor


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Majith on: 6/6/2012 | Points: 10
Read Only :

Read Only is Runtime Constant

Const:

Const is Compile time Constant

Login to post response