C# 引用类型 vs 值类型

值类型

    bool、byte、char、decimal、double、enum、float、int、long、sbyte、short、struct、uint、ulong、ushort
    此外还有用户自定义的struct

引用类型

    系统定义的两个Reference Type:object、string
    此外用class、interface、delegate修饰的类型都是引用类型

Value Type vs Reference Type

  • Value Type的变量直接包含值。
  • 当Value Type的变量赋值给另一个变量时,会将value的内容复制过去;而Reference Type只会将引用复制给另一个变量。
  • 与Reference Type不同,不能从Value-Type中派生新的class。
  • 与Reference Type不同,不能将null赋值给Value-Type的变量。

参考:Reference Type  , Value Type

猜你喜欢

转载自blog.csdn.net/zhanghui_hn/article/details/41824143