我需要更改從GetCell方法獲得的數組單元格對象。當我嘗試更改收到的對象時,它不會更改原來的對象。爲什麼對象引用不能引用預期的對象?
這是它的外觀在代碼:
// this is in MyClass
A[,] arr = new A[100,500];
// this is in main class
MyClass GetAAt(Point p) { return myClass.arr[p.X,p.Y]; }
var a = GetAAt(new Point(23,45));
a = new A(); // this only changes the local `a` but not the arr[23,45]
我在做什麼錯在這裏?
那麼我該怎麼做我想做的事? – user1306322
@ user1306322:你不能。 – SLaks
你仍然可以解決問題,你只需要努力一點就可以了。 [看我的回答](http://stackoverflow.com/a/13298796/1159478)爲例。 – Servy