If you want methods to return more than one value, declare the parameters as OUT or REF. Methods with OUT or REF are identical at compile time but different at run time. Hence you cannot overload a method one with OUT where as other with REF. You can overload method by
declaring one with OUT or REF and another without it.
The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword. Same applied for REF For example:
class OutExample
{
static void Method(out int i, out int j)
{
i = 44;
j= 22;
}
static void Main()
{
int value1;
int value2;
Method(out value1, out value2);
// value1 is now 44
//value2 is now 22
}
}
Although variables passed as an OUT arguments need not be initialized prior to being passed, the calling method is required to assign a value before the method returns.
declaring one with OUT or REF and another without it.
The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword. Same applied for REF For example:
class OutExample
{
static void Method(out int i, out int j)
{
i = 44;
j= 22;
}
static void Main()
{
int value1;
int value2;
Method(out value1, out value2);
// value1 is now 44
//value2 is now 22
}
}
Although variables passed as an OUT arguments need not be initialized prior to being passed, the calling method is required to assign a value before the method returns.
Comments