Can we assign values to read only variables?if yes then how?

 Posted by Hmanjarawala on 12/2/2011 | Category: C# Interview questions | Views: 3762 | Points: 40
Answer:

yes, we can assign values to read only variables either at a time of declaration or in constructors


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Akiii on: 12/4/2011 | Points: 10
It would have been better if you showed us one example.

Thank You
Akiii
Posted by: Rajeev.Shukla on: 12/5/2011 | Points: 10
You can assign the value to a readonly variable either when you declare it or in the constructor itself this no where
you can assign the value to a readonly variable.

e.g,

readonly int a=10

or

Class MyClass
{
readonly int a;
public MyClass()
{
a=10;
}
}

Login to post response

More Interview Questions by Hmanjarawala