I have a class with has variables of three types - constant , readonly , reference variable like this
public class Constants
{
public const int constA = 10;
public int readOnlyB = 10;
public readonly int referenceVarC = 10;
}
There is another project which references these variables from above like this -
class Program
{
static void Main(string[] args)
{
int a = Constants.Constants.constA;
int b = new Constants.Constants().readOnlyB;
int c = new Constants.Constants().referenceVarC;
Console.WriteLine("The value of a is {0}", a);
Console.WriteLine("The value of b is {0}", b);
Console.WriteLine("The value of c is {0}", c);
Console.ReadLine();
}
}
As per constant type variable nature - when i change the value of Constant and recompile the project but don't recompile the project which is consuming the constants , it refers to the old value of constant variable. Only on recompilation of the consuming project ,the new value of the constant project. This is understandable.
But why this nature is observed for readonly and reference variable also . There value, if changed in their creation project and the project gets compiled , should change in the consuming project , the consuming project being not recompiled, should change but i have observed them to point to old values.
As per me, when the consuming project is ran without recompilation , the referenced assemblies are loaded ( which are recompiled ) and the new values should be loaded.