C # heap and stack, value type and reference type, and empty type

Source: Internet
Author: User

1. Stack and stack

Stack is an advanced data structure that allocates memory space during compilation. Therefore, the size of the stack must be clearly defined in your code. Each pointer in the stack (when the variable is run) points to a memory area or space in the stack.

Heap is directly in the memory area. It develops memory for Stack reference. Usually, the built-in variable is that the value type is stored in the stack. Other objects provided by the. NET Framework, or the reference type defined by ourselves, are generally created in the heap and referenced by the stack variables. It is the memory space dynamically allocated during the program running. You can determine the heap memory size to be allocated based on the program running status.

Stack stores: Value Type, reference type "Address"

STACK: refers to the reference type "object" or the actual value of the reference type. It can be empty.

2. Value Type and reference type

 

Value Type: numeric type, which inherits from System. ValueType.

Reference Type: Class interface delegate Object string, all of which are inherited from System. Object

3. Empty type

An error is returned when you finish coding in.

Add one after the DateTime type?

This is an empty type.

An empty type can represent all values of the basic type, and a null value. An empty type can be declared in either of the following ways:

1. System. Nullable <T> variable

2. T? Variable

T is the basic type that can be empty. T can be any value type including struct, but cannot be a reference type.

Above ......

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.