原代码:
while (true)
{
Console.WriteLine("please add a string to ArrayList:");
str1 = Console.ReadLine();
if (str1="end")
break;
arr.Add(str1);
Console.WriteLine();
for (int i = 0; i < arr.Count; i++)
Console.Write("{0}", arr[i]);
Console.WriteLine("\n");
}
对以上的代码纠正,正确的代码为:
while (true)
{
Console.WriteLine("please add a string to ArrayList:");
str1 = Console.ReadLine();
if (str1=="end")
break;
arr.Add(str1);
Console.WriteLine();
for (int i = 0; i < arr.Count; i++)
Console.Write("{0}", arr[i]);
Console.WriteLine("\n");
}
现在运行正常了,希望对初学C# 的朋友们能有所帮助。