Rewrite this method here with a different variable name for the purpose of example:
public static void test(Node PassedNode)
{
PassedNode.key = 1111;
PassedNode = null;
}
PassedNode
inside the test
method points to the Node parent = new Node();
object that was initially passed in and so when you modify the values of the properties of PassedNode
inside the test
method, then these changes will affect the object in the Main method because there's only one object. When you write PassedNode = null
then PassedNode
in the test
method doesn't point to the original object anymore and that's all that happens: the object itself still lives on. If you want to clear the original reference, then you need to do that in the calling method.