Summary of value type and reference type

Source: Internet
Author: User

. Net divides data types into value type and reference type)

A data with value type is stored in a variable in the stack. That is, allocate memory space in the stack and store the included values directly. The values represent the data itself. Data of the value type has a fast access speed.

A data with reference type does not reside in the stack, but is stored in the heap. That is, allocate memory space in the heap. Instead of directly storing the contained values, it points to the value to be stored. The value indicates the address to which it points. When accessing a data with reference type, you need to check the content of the variable in the stack. The variable references an actual data in the heap. Data of the reference type has a larger storage scale and a lower access speed.
 
Value Type
(1) Where is this type allocated? Allocated on Stack
(2) How are variables represented? The value type variable is local replication.
(3) What is the base type? Must inherit from system. valuetype
(4) can this type be used as the base class of other types? No. The value type is sealed and cannot be inherited.
(5) What is the default parameter transfer? Variable is passed by value (that is, a copy of the variable is passed into the called function)
(6) can this type rewrite system. Object. Finalize. The value type cannot be placed on the stack, so it does not need to be terminated.
(7) Can I define constructors for this type? Yes, but the default constructor is retained (that is, the User-Defined constructor must have all parameters)
(8) When will this type of variable die? When they reach a defined scope

Cited type
(1) Where is this type allocated?
Allocated on managed stacks

(2) How are variables represented?
The reference type variable points to the memory occupied by the allocated instance.

(3) What is the base type?
It can inherit from any type except system. valuetype, as long as the type is not sealed's

(4) can this type be used as the base class of other types?
Yes. If this type is not sealed, it can be used as a base class of other types.

(5) What is the default parameter transfer?
Variables are passed by reference (for example, the address of the variable is passed into the called function)

(6) can this type rewrite system. Object. Finalize ()?
It can be overwritten indirectly.

(7) Can I define constructors for this type?
Of course!

(8) When will this type of variable die?
When the managed heap is reclaimed.

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.