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

后端 未结 5 1665
天涯浪人
天涯浪人 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:29

    Boxing (which is the process that happens here) is pretty nicely explained in the following article with examples at what happens in memory.

提交回复
热议问题