out Arguments
Added in ??
Passing Out
Very similar to reference parameters but with two main differences:
1) use the keyword "out"
2) the variable does not have to be assigned before the method is called
What about object types ?
Always ByRef regardless unless you manually clone / serialise the objects first in memory
The out parameter can be used to return the values in the same variable passed as a parameter of the method. Any changes made to the parameter will be reflected in the variable.
public class mathClass
{
public static int Mehod_TestOut(out int iVal1, out int iVal2)
{
iVal1 = 10;
iVal2 = 20;
return 0;
}
public static void Main()
{
int i, j; // variable need not be initialized
System.Console.WriteLine(Method_TestOut(out i, out j));
System.Console.WriteLine(i);
System.Console.WriteLine(j);
}
}
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext