I have a class defined as follows:
class foo
{
private string _bar;
public string Bar
{
get { return _bar; }
set { _bar = value; }
}
}
Look into the following operations:
foo myFoo = new foo();//Creating an object of foo
myFoo.Bar = "sample";//assign value for bar
foo currentFoo = myFoo;//Assign the object to another object
currentFoo.Bar = "newValue";//Change the value of newly created object.
In this scenario, after the final step value of bar
in both the object will became newValue
where as the value of object(.net) type is not reflecting like this:
object obj = "currentValue";//assign some value
object newObj = obj;//assign object to another object
newObj = "Changed Value";//change the value of new object.
Why it is not getting updated the value of old object?what will be the reason? Is it possible to create class's objects Like this?
Updates:
I have checked the following scenario too:
foo myFoo = new foo();
myFoo.Bar = "sample";
object currentFoo = myFoo;
((foo)currentFoo).Bar = "newValue";
//Here also both the objects get updated.