C#中让某个控制台程序在输入Q前一直执行下去的问题

namespaceConsoleApplication4{publicclassTravel{privateinttourCost=0;privateStringtour... namespace ConsoleApplication4
{
public class Travel
{
private int tourCost = 0;
private String tourLocation;
public int TourCost
{
get
{
if (tourLocation == "北京")
return tourCost = 1000;
else if (tourLocation == "上海")
return tourCost = 1500;
else if (tourLocation == "广州")
return tourCost = 2000;
else
return 0;
}
}
public String TourLocation
{
get
{
return tourLocation;
}
set
{
if (value != "北京" && value != "上海" && value != "广州")
tourLocation = null;
else
tourLocation = value;
}
}
class Program
{
static void Main(string[] args) //每次输入地点前都需要输入go 不知怎么解决
{
Console.WriteLine("请输入go开始程序,输入Q/q退出程序!");
String testString = Console.ReadLine();
while(testString!="Q"&&testString!="q")
{
Travel testobj = new Travel();
testobj.TourLocation =Console.ReadLine();
Console.WriteLine(testobj.TourCost);
Console.ReadLine();
}
}
}
}
}
每次输入地点前都需要输入一次go 怎样修改能够只输入一次(或者不输入)go就一直执行下去
展开
 我来答
百度网友ce7f3ccb4
2015-04-08 · TA获得超过1950个赞
知道大有可为答主
回答量:2299
采纳率:0%
帮助的人:1876万
展开全部
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();
}
追问
谢谢了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
greystar_cn
2015-04-08 · 知道合伙人软件行家
greystar_cn
知道合伙人软件行家
采纳数:16407 获赞数:17260
本人主要从事.NET C#方向的技术开发工作,具有10多年的各类架构开发工作经验。

向TA提问 私信TA
展开全部
String testString =null;
while((testString=Console.readline())!="Q")
{
your code here
}

while里赋值并同时判断是否是Q,要一起的,不能放外面。
追问
谢了
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式