CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS MICROSOFT C# DETAILS
Question :


What is the difference between const and static read-only?




Category C# Interview Questions
Rating (0.0) By 0 users
Added on 7/28/2006
Views 1920
Rate it!
Answers:

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).



both are used to define constants in the program..difference is that 'const' is evaluated at compile time..where as readonly will be evaluated at runtime.



 Posted by: Chandralekha Kasturi    

Contact Chandralekha Kasturi  Contact Chandralekha Kasturi

Both can not be changed.
readOnly --> can be intialized at runtim (should be initialzed at declaration time or in class contructor())
const --> can be initialzed at compile time (should be initialzed at declaration time itself)



 Posted by: Murugesan Bakthavachalam    

Contact Murugesan Bakthavachalam  Contact Murugesan Bakthavachalam

Both can not be changed.
readOnly --> can be intialized at runtim (should be initialzed at declaration time or in class contructor())
const --> can be initialzed at compile time (should be initialzed at declaration time itself)



 Posted by: Murugesan Bakthavachalam    

Contact Murugesan Bakthavachalam  Contact Murugesan Bakthavachalam


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
How to fill datalist usinf XML file and how to bind it,code behind language is c#

View Answer
WHAT IS THE ADVANTAGE OF SERIALIZATION?

View Answer
How we hand sql exceptions? What is the class that handles SqlServer exceptions?

View Answer
What is indexer? where it is used plz explain

View Answer
can we inherit the java class in C# class,how?

View Answer
We declare an integer variable 'x' in C# as

View Answer
A code block in C# is enclosed between

View Answer
To read user input from the console, the following statement is used

View Answer
The following is a correct call to the Main() function

View Answer
All the C# programs must have the following statement

View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C# Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/9091/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.77