C # basic value type and reference type,

Source: Internet
Author: User

C # basic value type and reference type,

Value Type: int double char bool decimal struct enum value stored on the memory Stack

Reference Type: string Array, custom class interface, delegated value stored in heap

Value Transfer: Pass the value type as a parameter, and pass the value itself ---- Note: ref can change the value transfer to reference.

Reference transfer: Pass the value of the reference type as a parameter, and pass the reference

Static void Main (string [] args) {int number = 10; Test (number); Console. writeLine (number); Console. readKey () ;}static void Test (int n) {n + = 10;} pass the num value to n, and the cmd result is 10; static void Main (string [] args) {int number = 10; Test (ref number); Console. writeLine (number); Console. readKey () ;}static void Test (ref int n) {n + = 10;} transmits the num address to n. In this case, num and n point to an address, and the cmd result is 20;

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.