I want to change the value of a static readonly field, the codes executes without any exception, but a very strange thing is:looks it is effected when use reflection, but not really working.
private class TestReadOnly
{
public static readonly int Field;
}
[TestMethod]
public void TestReadOnlyField()
{
FieldInfo field = typeof(TestReadOnly).GetField(nameof(TestReadOnly.Field));
Console.WriteLine(field.GetValue(null));
field.SetValue(null, 0xFF);
Console.WriteLine(field.GetValue(null));
Console.WriteLine(TestReadOnly.Field);
}
output:
0
255
0
my question is:is there any solution to make theme same?