In-depth C #

Source: Internet
Author: User

Value type: Duplicates the real value (stack) on the stack, mainly including data types (int,float,double and enumerations, etc.)

Value types originate from: System.ValueType

References to all types of reference types exist in the stack.

Reference type: The Real object property (heap) of real objects stored on the heap, mainly including (classes, interfaces, arrays)

Value types originate from: System.Object

Methods and Features:

public void Say () {

}

(1) Return value

(2) Access modifiers

(3) Method name

(4) Method body

(5) Parameters of the method

Definition of structure:

Access modifier struct struct name {

Structural body

}

You can have fields in the structure, or you can have methods

When defined, a field in a struct cannot be assigned a value

Packing and unpacking

The process of converting a value type to a reference type is called boxing, which is called unpacking

Unnecessary packing and unpacking should be minimized and the performance loss is greater.

Value parameter passing:

Reference parameter passing:

(Basic data types, such as, shape, float, character, bool, and struct are value types; arrays, interfaces and classes are reference types)

When a value type parameter is passed using a value method (without a ref decoration), the modification of the parameter in the method does not persist

When a reference type parameter is passed using a value method (without a ref decoration), the modification of the parameter in the method is preserved

When you pass a value type or reference type parameter by using a reference method (with ref decoration), the modification of the parameter in the method is preserved

In-depth C #

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.