gpt4 book ai didi

c# - 有关与关键字/保留字 “out”中的使用有关的编译错误的问题

转载 作者:行者123 更新时间:2023-12-02 11:07:13 25 4
gpt4 key购买 nike

你好
我的代码有错误:
必须在控制离开当前方法之前将out参数'o_BlockingSquaresArr'分配给”
现在,此错误将每个方法的每个return语句用最后一个红色绘制。
我不明白我的特定代码有什么问题
请帮我,
提前致谢

internal bool isLegalMove(Square i_Move, out List<Square> o_BlockingSquaresArr) 
{
bool result;

if (m_GameBoard[i_Move.RowIndex, (int)i_Move.ColIndex].Coin != null)
{
result = false;
m_MessageBuffer = "You have enterd a square which is already
occupied, please try again...";

m_ErrorFlag=true;
}
else
{
result = checkIfThereIsAtLeastOneSeqInOneDirection(i_Move,out o_BlockingSquaresArr);
}
return result;

}

internal bool checkIfThereIsAtLeastOneSeqInOneDirection(Square i_Move, out List<Square> o_BlockingSquaresArr)
{
const int k_EightDirections = 8;
bool isSequenceFound, finalRes = false;

for (int i = 1; i <= k_EightDirections; i++)
{
isSequenceFound = checkOpponentSequenceInDirection(i_Move, (eDirections)i, out o_BlockingSquaresArr);
if (isSequenceFound)
{
finalRes = true;
}

}
return finalRes;
}

internal bool checkOpponentSequenceInDirection(Square i_Move, eDirections i_Direction, out List<Square> o_BlockingSquaresArr)
{
//I've shortened this code only relevant things
Square o_AdjacentSquare = new Square();
adjacentCoin = doSwitchAndRetrieveAdjacentCoin(i_Move, i_Direction, out o_AdjacentSquare);

// ...

if (isThereAnOpponentSequence)
{
o_BlockingSquaresArr.Add(o_AdjacentSquare);
}
return isThereAnOpponentSequence;
}

最佳答案

如编译器错误所述,必须在方法的任何非异常返回之前明确指定out参数。我在任何地方都看不到对o_BlockingSquaresArr的任何分配。为什么甚至将它声明为out参数呢?

关于c# - 有关与关键字/保留字 “out”中的使用有关的编译错误的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5438926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com