This is the program in question:
(这是有问题的程序:)
namespace TestStuff
{
public class Test
{
public int x;
}
class Program
{
static void Main(string[] args)
{
Test firstClass = new Test();
firstClass.x = 5;
Test secondClass = firstClass;
firstClass.x = 6;
Console.WriteLine(secondClass.x);
}
}
}
The output of this program is 6, I assume this is because Test secondClass = firstClass;
(该程序的输出为6,我认为这是因为Test secondClass = firstClass;
)
, makes secondClass point to firstClass instead of making a copy of firstClass. (,使secondClass指向firstClass,而不是复制firstClass。)
If i want to make secondClass a copy of firstClass, how would I go about that ? (如果我想将secondClass复制为firstClass的副本,该如何处理?)
ask by victorfaarvang translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…