I want these method parameters, restart and winner to update a field in main. however, it doesnt seem to work because it says the value is never used. But I'm using it, so I don't understand;
'''
static void Restart(bool restart, bool winner, string[,] nums, bool[,] trueIfX, bool[,] trueIfO)
{
Console.WriteLine("would you liked to start a new game? Y/N");
string input = Console.ReadLine();
bool correctInput = false;
do
{
if (input == "Y")
{
correctInput = true;
restart = false;
winner = false;
nums[0, 0] = "1"; nums[0, 1] = "2"; nums[0, 2] = "3";
nums[1, 0] = "4"; nums[1, 1] = "5"; nums[1, 2] = "6";
nums[2, 0] = "7"; nums[2, 1] = "8"; nums[2, 2] = "9";
'''
do you need to return
restart
andwinner
back to the method that had executed theRestart()
?You can use the
ref
orout
keywords to do itref
means to pass parameter by reference. This allows called function to update the parameter value for caller likeHowever having a lot of
ref
parameters can be weired. So you can create a class and use it to pass data into the method.like
this allows you to modify
RestartOptions
class members and keep method signatures intact.