CLR and type references
I have a full cross post for the code here: But I'm not getting any bytes :)
[http://asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=172322 ]
Why does the following happen?
string var;
string var2;
string var = "FISH";
var2 = var; // set reference var2 to point to address of var;
Now if I take the {var} and stuff into another process....
Session["MyVar"] = var;
And then modify {var2}
var2 = "DOG";
And then get the session value
var = Session["MyVar"];
The following is true;
var = "FISH";
var2 = "DOG";
Now I understand that strings are not value types and they are inherited from base object and that strings are immutable. So the afore makes sense to me....
But.......
If I create a class and then decorate it with the [Serializable] attribute and put some fields in the type like a string. And put some accessors via...properties on the type.
[Serializable]
public class Simple{
public Simple(){};
private string m_name;
public string Name{
get{ return m_name;}
set{ m_name = value;}
}
}
Now I perform the same paradigm as earlier:
Simple var;
Simple var2:
var.Name = "FISH";
var2 = var2;
Now both var.Name and var2.Name == "FISH";
But if I now Serialize the var Simple object ...
Session["MySimpleVar"] = var; // running State Server out of process!
And then do:
var2.Name = "DOG";
And now get the serialzed copy of var:
var = (Simple) Session["MySimpleVar"];
Both var.Name and var2.Name == "DOG"
WIERD?
Anyone?

