码迷,mamicode.com
首页 > 其他好文 > 详细

C# ValueTypes

时间:2014-07-18 18:18:20      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   strong   os   

C# ValueTypes

1、哪些类型是ValueType?

The value types consist of two main categories:

Structs fall into these categories:

2、内置C#值类型实际是C#内置类的alias。例如:

  bubuko.com,布布扣

3、The C# type keywords and their aliases are interchangeable. 

 

  bubuko.com,布布扣

4、以下2种初始化的是,一个会调用构造函数初始化,一个不会。

  int myInt;

  myInt = new int(); // Invoke default constructor for int type.

5、Data types are separated into value types and reference typesValue types are either stack-allocated or allocated inline in a structure. Reference types are heap-allocatedBoth reference and value types are derived from the ultimate base class ObjectIn cases where it is necessary for a value type to behave like an object, a wrapper that makes the value type look like a reference object is allocated on the heap, and the value type‘s value is copied into it. The wrapper is marked so the system knows that it contains a value type. This process is known as boxing, and the reverse process is known as unboxing. Boxing and unboxing allow any type to be treated as an object.

  Although ValueType is the implicit base class for value types, you cannot create a class that inherits from ValueType directly. Instead, individual compilers provide a language keyword or construct (such as struct in C# and Structure…End Structure in Visual Basic) to support the creation of value types.

 

参考:

1、http://msdn.microsoft.com/zh-cn/library/ya5y69ds.aspx

2、http://msdn.microsoft.com/zh-cn/library/s1ax56ch.aspx

3、http://msdn.microsoft.com/zh-cn/library/system.valuetype(v=vs.110).aspx

C# ValueTypes,布布扣,bubuko.com

C# ValueTypes

标签:style   blog   http   color   strong   os   

原文地址:http://www.cnblogs.com/tekkaman/p/3853437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!