Can we initialize or assign values to Read-only variables
in any method other than Constructor?

 Posted by vishalneeraj-24503 on 12/26/2013 | Category: C# Interview questions | Views: 858 | Points: 40
Answer:

No,we can not initialize or assign values to Read-only variables because they can only be used to initialize either in Variable Declaration or in Constructor only.

If we assign values in any method,then it will give us Compile-Time error as

"A readonly field cannot be assigned to (except in a constructor or a variable initializer)"


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response