public struct StructHouse{
public int number;
}
public class ClassHouse{
public int number;
}
public class Test{
public TestForStruct testForStruct;
public ClassHouse classHouse = new ClassHouse();
public StructHouse structHouse = new StructHouse();
SendRef1(ref classHouse);
testForStruct.SendRef2(ref structHouse);
}
public class TestForStruct{
public StructHouse structHouse;
public void (ref classHouse);
public void SendRef2(ref StructHouse structHouse){
this.structHouse = structHouse;
this.structHouse.number = 1; //THIS DOESN'T UPDATE THE VALUE FOR 'Test'
//BUT IT DOES UPDATE IF I SEND REF CLASS INSTEAD OF REF STRUCT
}
e:如果我在'SendRef1'中更改'number'的参考值,则会在Test类中更新该值,但在更改SendRef2中的值时它不会更新。有人可以解释一下吗?
提前致谢。
答案 0 :(得分:0)
这一行正在复制结构。
this.structHouse = structHouse;
您只能在副本上更改number
的值。