私が苦労しているばかげた質問があります。
ネストされた for ループを使用して C# 多次元配列をステップ実行しようとしていますが、必要な結果が得られず、コードの愚かな問題だと考えています。
string search = txtString.Text;
int iLoop;
int jloop;
int iResult = -1;
for (iLoop = 0; iLoop < sounds.GetLength(0) ; iLoop++)
{
for (jloop = 0; jloop < sounds.GetLength(1) ; jloop++)
{
string result;
result = sounds[iLoop,jloop];
if (result == search)
{
iResult = iloop;
}
}
}
if (iResult == -1)
{
MessageBox.Show("Result not found");
}
else
{
MessageBox.Show("Result found at position " + iResult);
}
}
配列を検索し、答えが見つかった場合は肯定的な結果を返しますが、結果の位置は常に「位置 1 で見つかった結果」です。
私は何を間違えましたか?