class test
{
public int a;
}
struct test
{
public int a;
}
void test()
{
List <test > tt= new List<test>();
test aa = new test();
aa.a = 99;
tt.Add(aa);
test cc = tt.First();
cc.a = 88;
}
这个例子中test如果是类,则cc的值改变可以改变tt中列表的内容,如果是结构体则不能,说明类是引用类型从堆中获取了内存地址给cc,而结构体则是拷贝了tt中的内容给cc在栈上。