比方說,我們有一個程序,是這樣的:如何確定值是否被複制或引用?
namespace Example
{
class Program
{
static void Main(string[] args)
{
Storage MainStorage = new Storage();
PrintData Printer = new PrintData();
Printer.GetStorage(MainStorage);
}
}
class Storage
{
//Stores some data
}
class PrintData
{
Storage storage;
public void GetStorage(Storage storage)
{
this.storage = storage;
}
public void Print()
{
//Prints data
}
}
}
這只是一個例子,使代碼不會是完美的,但我的問題是,在這種情況下沒有的GetStorage()
方法使MainStorage
對象的副本或做它提到它呢?
引用類型不會自動複製。 – Andrey