What will happen,if we compile below code?

public readonly string status_deactive;

public void initialize_readonly_value()
status_active = "DD";

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

It will not compile properly,because it will give below error

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

We can only initialize readonly variables at the time of declaration or in class constructor.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response