当我试图访问多行输入时,以下程序将进入无限循环,您是否知道为什么它不起作用?当迭代字符数组时,无限循环
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' - 直接问题将被清除 –