You are not even trying to make some object null, you create another reference and make it null. This null reference is itself a
stack variable (do you understand how stack works?), so it disappears after the call to
Fun
is done. You do nothing to the reference
AAA
, and of course nothing to the object referenced by this reference.
You could make a reference null by this simple method:
static void Nullify(ref object @object) {
@object = null;
}
It also does not do anything to the referenced object, but it does modify the reference passed be reference.
Maybe this question really can help you to understand things, but don't expect that this exercise can teach you any useful techniques or something. Rather, you need just to draw a picture, how reference types work. When you work with a reference types with some variables or members, such variables and members are separate object, references; but there is also a referenced object, referenced by such variable or member.
When you assign anything, even null, to a variable or a member of a reference type, you never ever modify the referenced object itself; you can only modify it if you use a member of that object.
In practice, passing a reference-type object by reference makes little to now sense; the object itself, even if passed by value, is already referenced. And you don't need to assign null to a reference; however, you can do it just to indicate some condition, to be later checked up using "if" statement.
—SA