using UnityEngine;
using System.Collections;
public class A {
public float a;
public A(float value)
{
this.a = value;
}
}
public struct S
{
public string s;
public S(string value)
{
this.s = value;
}
}
public class TT : MonoBehaviour {
void Start () {
A a1 = new A(3.14f);
A a2 = new A(6.28f);
a1 = a2;
a2.a=99.9f; print(a1.a); //99.9
//a2= new A(99.9f); print(a1.a); //6.28 引用类型a2 New()之后都会分配新的地址,且a1指向a2的旧地址,a1的旧地址没有被任何变量引用,内存被回收
S s1 = new S("SIKI");
S s2 = new S("KISMY");
s1 = s2;
s2.s = "XXX";
print(s1.s); //KISMY
}
}
using System.Collections;
public class A {
public float a;
public A(float value)
{
this.a = value;
}
}
public struct S
{
public string s;
public S(string value)
{
this.s = value;
}
}
public class TT : MonoBehaviour {
void Start () {
A a1 = new A(3.14f);
A a2 = new A(6.28f);
a1 = a2;
a2.a=99.9f; print(a1.a); //99.9
//a2= new A(99.9f); print(a1.a); //6.28 引用类型a2 New()之后都会分配新的地址,且a1指向a2的旧地址,a1的旧地址没有被任何变量引用,内存被回收
S s1 = new S("SIKI");
S s2 = new S("KISMY");
s1 = s2;
s2.s = "XXX";
print(s1.s); //KISMY
}
}