C# does pass by value by default, however in
funcChange(Foo bar)
bar is a reference to an object of type Foo
. This reference is a copy of the input argument, however it refers to the same object on the managed heap. This is why you can mutate bar
in funcChange
.
In funcNull
,
bar = null;
sets the local variable bar
to null. Since bar
is a copy of the input argument, it does not affect foo
in the caller.