C # parameter keyword out

Source: Internet
Author: User

The out keyword causes the parameter to be passed through reference. This is similar to the ref keyword. The difference is that
The variable must be initialized before being passed.

When you want the method to return multiple values, it is useful to declare the out method, for example:

Int I;
String str1, str2;
Useout (Out I, out str1, out str2 );
// I is now 44
// Str1 is now "string 1"
// Str2 is (still) NULL;

Public
Static void useout (Out
Int I, out
String str1, out string str2)
{
I = 44;
Str1 = "string 1 ";
Str2 = NULL;
}

Note:

1. When the out parameter is used, the out keyword must be displayed for both the method definition and method usage.

2. Although
The variables passed by parameters do not need to be initialized before being passed, but you need to call a method to assign values before the method returns.

3. attributes are not variables, so they cannot be used as out
Parameter transfer

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.