Differences between reference parameter ref and output parameter out in C #

Source: Internet
Author: User

Record the differences between the reference type and the output type parameters in C # today. The following describes the differences.

Ref (reference parameter) transmits data to the method through the memory address of the actual value, so the change to it will affect its actual memory address.

Out (output parameters) is the same as ref and does not open up new memory addresses. However, one feature of output parameters is that they do not need to be initialized when calling methods and must be initialized before returning them.

Example:

Class test

{

Public string outTest (string p, out path)

{

Response. write (p );

Path = "test ";

}

Static void main ()

{

String strPath;

String strp;

OutTest (strp, out strpath)

Response. write (strpath );

}

}

Now you can understand.

Now you can understand.

Related Article

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.