Output parameters in C#

Output parameter is very interesting concept about passing parameters in C#, basically output parameters are used to pass result back to the calling method.For it we use out keyword. Output parameter does not create a new storage location similar to reference parameters.
It is necessary to use out keyword to declare parameter when corresponding actual parameters declared as out.

output parameters in C#

In the following example we pass the i integer type value as out parameter that has no value. after calling GetNumber() method, value of i get change to 5.

class Shape
{  
     public void main()
    {
        int i;
        GetNumber(out i);
        Console.WriteLine(i);
    }
    public void GetNumber(out int x)
    {
        x = 5;
    }   
}