I call the Clear method to set p to null, which is still available in the program below and can be printed.
Reply content:
I call the Clear method to set p to null, which is still available in the program below and can be printed.
This is the code of C #, you so directly to the P pass in, the equivalent of Person p1 = p
JS is the same, in fact, your function of P is only a shallow copy ah, if you want to direct the reference into the words, then you need to add one in front ref
Clear(ref p);static void Clear(ref Person p){
Your clear method inside that P (followed by P0 to express a convenient distinction) is not an incoming variable p, it is pointing to the same piece of memory with P, that is, pointing to the same object, but you in the method of the P0 is assigned to empty, P0 no longer point to that object, P has no effect, The local variable p in the Main method still points to the original object.