while 루프를 입력하자마자 프로그램은 행과 열 값을 가져 오지 않고 Index out of range 예외를 throw합니다. 의 getInt는 값이 범위에 있는지 확인하는 동안 사용자의 입력을받을 수있는 방법이다2d 배열 인덱스가 범위를 벗어남 예외
while(filled>0)
{
row = getint("row: ");
row--;
column = getint("column: ");
column--;
fields[row, column]=getint("value: ");
filled--;
}
편집 : 경계의 밖으로 코드는 fields[row, column]
에서 일어날 수있는 경우
static int getint(string question)
{
string temp;
int tempint=0;
while (check != 0)
{
check = 0;
Console.Write("\nPlease enter the {0}",question);
temp = Console.ReadLine();
if(!int.TryParse(temp, out tempint))
{
check++;
}
if(question.Length<14 & (tempint<1 | tempint>9))
{
check++;
Console.WriteLine("Invalid Input");
}
}
return tempint;
}
"행 및 열 값을받지 않고"는 무엇을 의미합니까? 우리는 그 방법이 무엇인지,'필드의 크기가 무엇인지 모릅니다. [mcve]를 입력하십시오. –
while 루프를 입력하자마자 예외가 발생하면 문제는 아마도'getint()'에있을 것입니다.하지만 그 코드를 포함하지 못했습니다. – itsme86
많은 코드가 필요합니다. 예를 들어 아래에서 위로 읽으려고합니까? –