CSharp - What is the output: Use ref Parameter

Question

What is the output from the following code

using System;
class Program
{

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


Click to view the answer

Compile time error

Note

We need to initialize myVariable before passing it into the Changeme() method; otherwise, we'll encounter a compilation error.

Related Quiz