Can somebody explain this code to me why it compiles
class Foo
{
public int X = 4;
}
class TestReadOnly
{
public readonly Foo A = new Foo(); public void ChangeReadOnly() { A.X *= 2; }
}
class Program
{
static void Main(string[] args)
{
TestReadOnly tmp = new TestReadOnly(); Console.WriteLine("tmp.A.X : {0}", tmp.A.X);
tmp.ChangeReadOnly();
Console.WriteLine("tmp.A.X : {0}", tmp.A.X);}
}
I thought the readonly value can't be changed..
Here is my result:
tmp.A.X : 4
tmp.A.X : 8
Press any key to continue . . .