class Reflection
{
public Reflection (ref string f_s)
{
m_s = f_s;
}
private string m_s = null; // THIS IS WRONG! But how is right?
public string Str
{
get{ return m_s; }
}
}
class MainClass
{
[STAThread]
static void Main(string[] args)
{
string m = "Master";
Reflection r = new Reflection(ref m);
Console.WriteLine("Object: {0}, Reflection {1}", m, r.Str);
m = "Lomaster";
Console.WriteLine("Object: {0}, Reflection {1}", m, r.Str);
Console.ReadLine();
}
}
That is because m in 'm = "Lomaster"' becomes a new object, not the same object with an internal reference to a new string.
Semantic of references in c++ and IL is different.