Simply put, I am using a while loop to repeat a method, and each time the method is run the int “i” will increase by 1. Although I am having trouble calling the “NumberUp” method. error output is below.
Main method:
while (true)
{
NumberUp(0);
}
NumberUp Method:
public static void NumberUp(ref int i)
{
i++;
System.Console.WriteLine(i);
}
I keep getting the following error:
The best overloaded method match for ‘ConsoleApplication2.Program.NumberUp(ref int)’ has some invalid arguments
To call a method that takes a
refparameter, you need to pass a variable, and use therefkeyword:This passes a reference to the
xvariable, allowing theNumberUpmethod to put a new value into the variable.