I learnt the reference type parameter passing is just a copy of the reference. If you set the passed in refernece parameter point to another object inside the called method, the orginal reference will not change.
I have a test method to test the reference type parameter passing. A
refTest(SystemSwEvent systemSwEvent) method is called from that test method with a valid SystemSwEvent type object. Inside the
refTest() method, the
processEvScanDataAvailable(EvScanDataAvaialble systemSwEvent) method is called. Inside the
processEvScanDataAvailable(EvScanDataAvaialble systemSwEvent) method, I set the passed in reference parameter to
null. I expect the parameter in
refTest() should not be changed. But that is not true. It will be changed to null momentarily. why?
I suspect this is a debugger issue, and not representative of what's actually occurring inside the CLR.
Try using different variable names for your arguments, and this behavior will go away.
The debugger recognizes the name in the current context and shows the value. It's just a coincidence that you pointed your cursor at a place that actually triggered the currently executing method (the current context).
Also note you can use the Call Stack tool to inspect the parameters of caller methods.
Object references are by default (if you don't qualify them with
out) passed by value, so the method is receiving a copy of the object reference - setting that copy to
null doesn't change the original object reference, so what you claim to see is impossible and most likely you are just misinterpreting what you see in the debugger.
The debugger is getting confused because your parameter and variable have the same name. If you change the name of your parameter, you will notice that that debugger no longer gives information about the variable being passed into the method, but only gives information on the variable inside the method.
Simply change the name of that parameter, and you will no longer have this issue.