I am confused about how C# works in general when passing object instances.
This is the code I have trouble understanding:
public void foo()
{
SomeObj obj = new SomeObj();
obj.PropertyX = true;
bar(obj);
Console.Write(obj.PropertyX.toString()); //true or false?
}
public void bar(SomeObj obj)
{
obj.PropertyX = false;
}
In the code above if the objects instance is passed by reference, I would expect the Console to print false
. Is this how C# and OOP work?
Or does the instance of SomeObj
in foo()
preserve the state and the console prints true
?