Console.WriteLine("请输入go开始程序,输入Q/q退出程序!");
do
{
if(Console.ReadLine().ToUpper().Equals("Q"))
break;
Travel testobj = new Travel();
testobj.TourLocation =Console.ReadLine();
Console.WriteLine(testobj.TourCost);
}while(!testString.ToUpper().Equals("Q"))
或者
Console.WriteLine("请输入go开始程序,输入Q/q退出程序!");
String testString = Console.ReadLine();
while(!testString.ToUpper().Equals("Q"))
{
Travel testobj = new Travel();
testobj.TourLocation =Console.ReadLine();
Console.WriteLine(testobj.TourCost);
testString = Console.ReadLine();
}
String testString =null;
while((testString=Console.readline())!="Q")
{
your code here
}
while里赋值并同时判断是否是Q,要一起的,不能放外面。