C# ValueTypes

來源:互聯網
上載者:User

標籤:style   blog   http   color   strong   os   

C# ValueTypes

1、哪些類型是ValueType?

The value types consist of two main categories:

  • Structs

  • Enumerations

Structs fall into these categories:

  • Numeric types

    • Integral types

    • Floating-point types

    • decimal

  • bool

  • User defined structs.

2、內建C#實值型別實際是C#內建類的alias。例如:

  

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

 

  

4、以下2種初始化的是,一個會調用建構函式初始化,一個不會。

  int myInt;

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

5、Data types are separated into value types and reference types. Value types are either stack-allocated or allocated inline in a structure. Reference types are heap-allocated. Both reference and value types are derived from the ultimate base class Object. In 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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.