C # valuetypes

Source: Internet
Author: User

C # valuetypes]

1. What types are 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. the built-in C # value type is actually the alias of the C # built-in class. For example:

  

3. the C # type keywords and their aliases are interchangeable.

 

  

4. The following two types of initialization are: one will call the constructor initialization, and the other will not.

Int Myint;

Myint = new int (); // invoke default constructor for int type.

5. data types are separatedValue typesAndReference types. Value types are eitherStack-allocatedOr allocated inline in a structure. reference types areHeap-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.

 

Refer:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.