Using the out Parameter

Introduction

Did you ever need your method return more than one value? The out keyword can be used to do the same.

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 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
        Console.WriteLine(TestOut(out i, out j));
        Console.WriteLine(i);
        Console.WriteLine(j);
    }
}

To know more about Out parameter, click here.


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.