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