C#中的数据类型

DataType分为:
  Value Type(值类型,注意,struct也是值类型)
  Reference Type(引用类型)
The difference is that a value type stores its value directly, while a reference type stores a reference to the value.
These types are stored in different places in memory; value types in an area known as the stack, while reference types are stored in an area known as the managed heap.

Most of the more complex C# data types, including classes that we ourselves declare, are reference types. They are allocated upon the heap, have lifetimes that can span multiple function calls,and can be accessed through one or several aliases. The Common Language Runtime (CLR) implements an elaborate algorithm to track which reference variables are still reachable, and which have been orphaned. Periodically, the CLR will destroy orphaned objects and return the memory that they once occupied back to the operating system. This is done by the garbage collector.
  数据类型的存储位置隐含的说明了改数据类型在赋值语句环境中的执行方式。把一个值变量付给另一个值变量,会在堆栈中创建同一个数据的两个相同的副本。相反,把一个引用变量付给另一个引用变量,会在内存中创建对同一个位置的两个引用。

posted on 2006-03-02 21:39  无心三立  阅读(177)  评论(0编辑  收藏  举报

导航