无法将类型"string"隐式转换为"bool"

原代码:

         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# 的朋友们能有所帮助。
 

原文地址:https://www.cnblogs.com/jianfangkk/p/1367243.html