C#Struct堆栈
Struct若其内部含有堆对象,Struct的该对象放在堆上;
Struct当做参数传递时,其堆属性作为引用传递,值属性还是作为值传递;
struct TS
{
public int[] t1;
public int t2;
}
public void TF1(TS t)
{
int[] t1 = t.t1;
t1[0] = 2;
t.t2 = 20;
}
public void Main()
{
TS ts = new TS();
ts.t1 = new int[1];
ts.t1[0] = 1;
ts.t2 = 2;
TF1(ts);
Console.WriteLine(ts.t1[0]);
Console.WriteLine(ts.t2);
}
输出:
2
2