. NET value types and reference types

Source: Internet
Author: User

C # is a type-safe development language in which the data types are divided into value types (value type) and reference types (Reference type).

One, value types (value type)

    • Character: Char u+0000-u+ffff 16-bit Unicode character (in fact, the character is also an integral type)
    • Integral type: sbyte, Byte, short, ushort, int, uint, long, ulong
    • Float type: Float (7-bit valid), double (15 to 16-bit significant bit)
    • The decimal:128 bit data type, which has a higher precision (28 to 29 bit significant bits) and a smaller range than floating-point types, is suitable for financial and currency calculations.
    • Boolean: bool (TRUE or FALSE, true or false)
    • Structure: struct
    • Enum: enum

Value Type Summary:

    1. characters, integers, floats, decimal, and bool are all instances of struct types, and the values of these types are given by const constants MaxValue and MinValue within these types of structures.
    2. The struct (see * superscript) for the value types of character, integer, float, decimal, and bool are listed:
    3. Enum type is an enum Abstruct class type.
    4. Value types are implicitly derived from child System.ValueType.
    5. Enum and struct definitions should be at the same class or within the class but not inside the method.

struct-body ************************************************ for value types

Char Char

SByte sbyte

BYTE byte

Short Int16

UShort UInt16

int Int32

UINT UInt32

Long Int64

ULONG UInt64

Float single

Double Double

Decimal decimal

BOOL Boolean

*************************************************************************************************************** **

Second, reference type (Reference type, variable of reference type is also called object)

    • Class: Classes
    • Interface: interface
    • Delegate: Delegate
    • Object:. NET built-in reference types
    • String:. NET built-in reference types

Summary of reference types:

Class: Is an abstraction of an object with the same characteristics

Interface: Uniform constraint rules for seamless sharing of data and communication between objects of a homogeneous nature

Delegate: Similar to a pointer in C + +, the method name can be passed as a parameter, unlike a delegate that is type-safe.

Object:. The base class for all classes in net

String: A sequence of strings (0 or more Unicode characters)

Iii. comparison of value types and reference types

    1. Value types allocate storage space on the stack of memory, whereas reference types allocate storage on the heap of memory
    2. When a value type is assigned a copy is worth a copy, and the reference type assignment only saves the address of the applied object (. NET called "References")
    3. Value types allocate memory space faster than the application type allocates memory space, but duplicate value type assignments can cause excessive memory overhead and require a reasonable trade-off in memory overhead.
    4. Value types cannot contain null, and reference types can be null
    5. ......

. NET value types and reference types

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.