哦哦,看了你们三个的解释 我大概明白了。谢谢你们三位哈!作者: 冯鸿昌 时间: 2012-12-22 22:01
Value Types and Reference Typesare stored in defferent palces in memory;value types are stored in an area known as the stack, and reerence types are stored in an area known as the managed heap.It's important to be aware of whether a type is a value type or a reference type because of the different effect each assignment has.
In C#, basic data types like bool and long are value types.This means that if you declare a bool variable and assign it the value of another bool variable, you will have two separate bool values in memory..Later if you change the value of the original bool variable, the value of the second bool variable does not change. These types are copied by value.
In constract, most of more complex C# data types, including classes that you yourself declare, are reference types. Tyey are allocated upon the heap, have lifetimes that can span multipile function calls and can be accessed throuth one or several aliases.作者: 王靖雯 时间: 2012-12-24 15:19
关于引用类型,是存放在堆中的,由于堆中的内存空间是不连续的,我们在其中开辟空间时,首先遍历到第一块大于等于我们要申请的内存的空间,将它从这个内存中取出来,为了将来不造成内存的泄露,这个内存我们用完就得还回去,怎样还回去呢?我们就要记录它的地址,所以 我们需要用引用类型来标示它。空间是堆中空间,但是标识它的变量在栈中。 作者: 阮佳佳 时间: 2012-12-24 15:55
直白点儿说:值类型就是现金,要用直接用;引用类型是存折,要用还得先去银行取现。作者: 鲜学良 时间: 2012-12-25 14:26
1.将一个值类型变量赋给另一个值类型变量时,将复制包含的值。引用类型变量的赋值只复制对对象的引用,
而不复制对象本身。
2.值类型不可能派生出新的类型:所有的值类型均隐式派生自System.ValueType。但与引用类型相同的是,结
构也可以实现接口。
3.值类型不可能包含null 值:然而,可空类型功能允许将null 赋给值类型。
4.每种值类型均有一个隐式的默认构造函数来初始化该类型的默认值。