CSharp - What is the output: out parameter initialization

Question

What is the output from the following code


using System;

class Program
{
    static void Change(out int x)
    {
        x = x * 2;
        Console.WriteLine("Inside Change(), myVariable is {0}", x);//50
    }
    static void Main(string[] args)
    {
        int myVariable;
        Change(out myVariable);
        Console.WriteLine("Inside Main(), myVariable={0}", myVariable);//50
    }
}


Click to view the answer

Compile time error

Note

For the out parameter, we need to assign a value before it comes out of the function.

Related Quiz