c# - 初始值从未使用过,代码运行时方法参数未更新
问题描述
我希望这些方法参数,重新启动和获胜者更新 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";
'''
解决方案
您收到此警告/错误是因为warning
从未实际用于某事。一旦将它传递给另一个函数,在 if 语句等中使用它,警告/错误就会消失。
把它想象成有一个建筑商作为你的员工,你给了员工一把锤子。是的,你给了你的工人它需要的东西,但现在他们站在周围等着你用它们做某事。
推荐阅读
- tensorflow - TensorFlow:将字符串解析为两个张量
- django - ManagementForm对应的数据不存在或已被修改
- javascript - “How to fix the 'div panel' in either CSS or JavaScript from closing
- javascript - 如何在jQuery中获取窗口选择中的单词数
- php - 使用 MediaWiki 1.32 访问 wiki 页面时出现问题,PHP 已过时
- python - 如何使物体在同一高度永远反弹
- javascript - innerHTML 的问题 - 无法识别来自 css 的类
- javascript - 有没有办法在没有 .then 的情况下每次都解开一个承诺?
- scala - 组合地图的所有值,其中每个值都是一个数据框
- javascript - 如何在移相器 3 中以随机延迟循环函数回调?