C#.net核心2.0,循环过多
我有一个相当简单的for循环,我们已经使用了数千次,但是我得到了一个奇怪的错误。由于我怀疑C#.net core中是否存在故障,我一直在寻求有关我的错误的帮助:C#.net核心2.0,循环过多,c#,for-loop,.net-core,C#,For Loop,.net Core,我有一个相当简单的for循环,我们已经使用了数千次,但是我得到了一个奇怪的错误。由于我怀疑C#.net core中是否存在故障,我一直在寻求有关我的错误的帮助: public Int2DBoard GetNonMatchingSquaresThisBoardOnly(Int2DBoard other) { // create a tempBoard: Int2DBoard tempBoard = new Int2DBoard("Differ
public Int2DBoard GetNonMatchingSquaresThisBoardOnly(Int2DBoard other)
{
// create a tempBoard:
Int2DBoard tempBoard = new Int2DBoard("Different");
// create a match bool to hold our result:
bool match = false;
// match this board items against other board
for (int i = 0; i < board.Count; i++)
{
for (int j = 0; j < other.board.Count; i++)
{
if (other.board[j] == board[i])
{
match = true;
break;
}
}
if (!match)
{
tempBoard.board.Add(board[i]);
}
}
return tempBoard;
}
public Int2DBoard getnonmatchingsquaresthisboard only(Int2DBoard other)
{
//创建临时板:
Int2DBoard tempBoard=新的Int2DBoard(“不同”);
//创建一个匹配布尔来保存我们的结果:
布尔匹配=假;
//将此板项与其他板项匹配
对于(int i=0;i
当我运行此命令时,我会得到一个越界错误,检查此命令后,我会得到以下信息:
i=2;
板数=2
这怎么可能?该函数清楚地说明您在内部循环中增加的是
i
而不是j
:
for (int j = 0; j < other.board.Count; i++)
for(int j=0;j
将其更改为:
for (int j = 0; j < other.board.Count; j++)
for(int j=0;j
您在内部循环中增加的是i
而不是j
:
for (int j = 0; j < other.board.Count; i++)
for(int j=0;j
将其更改为:
for (int j = 0; j < other.board.Count; j++)
for(int j=0;j
在内环中有i++
而不是j++
在内环中有i++
而不是j++