首页 > 解决方案 > 初始值从未使用过,代码运行时方法参数未更新

问题描述

我希望这些方法参数,重新启动和获胜者更新 main 中的字段。但是,它似乎不起作用,因为它说该值从未使用过。但是我正在使用它,所以我不明白;

'''
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";
'''

标签: c#

解决方案


您收到此警告/错误是因为warning从未实际用于某事。一旦将它传递给另一个函数,在 if 语句等中使用它,警告/错误就会消失。

把它想象成有一个建筑商作为你的员工,你给了员工一把锤子。是的,你给了你的工人它需要的东西,但现在他们站在周围等着你用它们做某事。


推荐阅读