當我試圖訪問多行輸入時,以下程序將進入無限循環,您是否知道爲什麼它不起作用?當迭代字符數組時,無限循環
namespace AlternatingCharacters
{
class Program
{
static void Main(string[] args)
{
int N = Int32.Parse(Console.ReadLine());
string[] str = new string[N];
for (int i = 0; i < N ; i++)
{
str[i] = Console.ReadLine();
}
for (int i = 0; i < str.Length; i++)
{
int count = 0;
Char[] strArray = str[i].ToCharArray();
for (int j = 0; j < strArray.Length; j++)
{
if (strArray[i] == strArray[i + 1])
{
count++;
}
}
Console.WriteLine(count);
Console.ReadLine();
}
}
}
}
請編輯標題,只包含問題。任何其他細節/問題應該是該職位的一部分 – Anton
我認爲你在這裏有一個_bigger_問題,而不是無限循環。你應該學習如何調試你的代碼。閱讀Eric Lippert:[如何調試小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)同樣來自MSDN:[在Visual Studio中調試](https ://msdn.microsoft.com/en-us/library/sc65sadd.aspx) –
而不是匿名'i'和'j',使用'stringIndex'和'characterIndex' - 直接問題將被清除 –