Two differences between the referenced parameter and the output parameter (I used to know the first parameter)

Source: Internet
Author: User
1. The reference parameter (REF) must be explicitly assigned a value before it can be passed as a reference parameter in a function member call. The output parameter (out) you do not have to assign values explicitly before being passed as an output parameter in a function member call. You must assign values before the function member returns normally.

2. In a function, the reference parameter (REF) is regarded as the initial value assigned, and the output parameter (out) is regarded as the initial value not assigned.

Example:

Private void setage (ref int _ oldage, out int _ newage)
{
_ Newage = 2; // The value of out must be assigned.
}

Public void main ()
{
Int oldage = 0; // ref must be assigned a value in advance
Int newage = 1; // The out advance value is invalid in the function.
Setage (ref oldage, out newage );
}

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.