when I do:
var foo = new Customer("Peter");
var sth = foo;
var foo2 = foo;
and then:
foo = new Customer("Dave");
only foo is updated and the others will still be “Peter”.
But when I do:
foo.Name = "Dave";
then all the objects are updated. Why is this?
When it comes reference types the variable (foo in your example) stores only the reference. When you assign new value to variable you’re changing only this variable, not an object it referenced before.
The behavior you expect could be done with above code. If you set Customer.Current to some value then every code that asks for Customer.Current will get previously set Customer. However, static variables are usually not good design choice and come with their set of problems (testability, threading issues, etc.).