设置一个类型的引用类型设置为null不会影响复制类型?类型、设置为、null

2023-09-04 02:11:49 作者:老师,作业跑了

为什么这会产生0?

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

不b指向了同一个位置,并设置=空有效地使b空?

Doesn't b point to the same location and setting a = null effectively makes b null?

推荐答案

一张图片胜过千言万语:

A picture is worth a thousand words: