12-3

you should declare a type as a value type if all the following statements are true:

•The type acts as a primitive type. Specifically, this means that the type is a fairly simple
type that has no members that modify any of the type's instance fields. When a type
offers no members that alter its fields, we say that the type is immutable.
• The type doesn't need to inherit from any other type.
• The type won't have any other types derived from it.

Here are some of the ways in which value types and reference types differ:(值类型与引用类型的几点不同)

值类型有两种表现形式:boxed or unboxed,而引用类型就一直是boxed的

值类型很多方法都是override System.Object的,所以在一定程度上导致了性能的下降。

值类型不能被继承也是一大硬伤。

都为空时,值类型为null type,不会抛出异常。而引用类型则为空指针时却还要使用,就会抛出空异常。

值类型的复制会复制所有值遇,而引用类型只会内存的地址。

几个引用类型可以只指向一个托管堆,而值类型分别属于不同的object,是相对独立的。

unboxed类型的值类型不是放在heap上的,他们随实例类型的消失而消失。

Boxing and Unboxing Value Types

越看越没劲,学的东西太多,不知道学什么好!哎!

目前看的这些东西,貌似大部分也都了解一些,一知半解的,想了想还是去买了本你必须知道的.net把。

posted @ 2009-12-03 11:07  Tmac_  阅读(111)  评论(0编辑  收藏  举报