Modify the value of readonly varibale
The readonly keyword is a modifier that you can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.
This is how we declare a readonly variable:
public readonly int objreadonly = 100;
You can only change the value of a readonly variable at the constructor level of the same class.
An Excerpt about readonly is :
A readonly field can only be set upon field initialization or in a constructor. This gives considerable benefit for ongoing maintenance because you can ensure it was set when the object was created and not modified since. Though there is no performance benefit.
I have used a little practical demonstarion of this.
class Readonly
{public readonly int objreadonly = 100;
Readonly()
{
}
public void ChangeValueofReadonly()
{
objreadonly = 200;
}
}
class Program
{
static void Main(string[] args)
{
}
}
If you notice I tried to change the value of readonly object "objreadonly" but I'm not successful at changing its value, it issues the error "A readonly field cannot be assigned to (except in a constructor or a variable initializer)" also depicted below in the snap shot.

In other words you can't change its value at method level at class level. It can change at constructor level only.
Let's do it :

This is a small demonstration that I hope will help you somewhere down the line.

Sachin KaliaPosted May 31, 2013, 11:07 PM
Thanks Bro
Vithal WadjePosted May 31, 2013, 10:59 PM
not an issue sir.keep it up posting
Sachin KaliaPosted May 31, 2013, 4:22 PM
actually this article is more about who are very new to c# and arenot muchfamiliar with this termonology...
Sachin KaliaPosted May 31, 2013, 4:19 PM
runtime means..at constructor level only.if you want to change it at method level..thn it wont be possible..
Vithal WadjePosted May 31, 2013, 4:09 PM
sir i wants explain one thing that is whats differnce between read only and constant that is we can change the value of ready only at runtime and we can not be change the value of constant at run time means i wants to say thei is nothing to new in above article that you trying to explain but thatnks for sharing