Setting a type reference type to null doesn't affect copied type?

后端 未结 5 1660
天涯浪人
天涯浪人 2020-12-09 12:57

Why does this produce \"0\" ?

object a = 0;
object b = a;
a = null;
Console.WriteLine(b.ToString()); // Produces \"0\"
Console.Read();

Does

5条回答
  •  攒了一身酷
    2020-12-09 13:26

    Here's a description of what's going on:

    object a = 0; // pointer a = 0xSomeA
    object b = a; // pointer b = 0xSomeB
    a = null; // nulling a, now 0x00; b still the same
    

提交回复
热议问题