【OOP】static參考變數欄位
/
0 Comments
紀錄一下同事提到的static參考變數欄位蠻容易搞混的情況。
程式碼如下:
void Main()
{
 test = new Obj1 { name = "tt" };
 test.Dump();
 
 var a = Call();
 a.Dump();
 
 a.name = "t2";
 a.Dump();
 
 //要點一
 test.Dump();
 
 a = null;
 a.Dump();
 
 //要點二
 test.Dump();
 
}
public Obj1 Call()
{
 return test;
}
public static Obj1 test;
public class Obj1
{
 public string name { get; set; }
}
主要容易搞混的點分別在程式碼上標示出來了,兩個要點: