Coding is used to describe the out and ref parameters.

Source: Internet
Author: User

 

Void main (string [] ARGs)
{
// Test the transfer of out and ref Parameters
Int A; int B; int c = 2; // (1) the out parameter can be not initialized before calling, but the ref parameter must be initialized.
Testoutref (out a, out B, ref C); // (2) when calling a method, you must add out or ref before the Parameter
Console. writeline (string. Concat (a + "," + B + "," + C ));
Console. Read ();
}

// The out parameter must be used inside the method, and the ref parameter can not be used (the usage of the out parameter means that the method can have multiple return values)
Static void testoutref (Out int A, out int B, ref int C)
{
A = 1;
B = 2; // A, B must be used inside the Method
C = 3; // C can be left empty in the Method
}

ProgramRunning result: 1, 2, 3

Static

 

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.