C#中case语句如何返回主函数!用return不可以,它就停止了整个case语句。我想它返回主程序继续其他功能。
staticvoidMain(string[]args){PrintMainMenu();List<employee>list=newList<employee>();e...
static void Main(string[] args)
{
PrintMainMenu();
List<employee> list=new List<employee>();
employee ep = new employee();
string a = Console.ReadLine();
switch (a)
{
case "1":
AddEmployee(list, ep);
break;
case "2":
break ;
case "3":
break;
case "4":
break;
case "5":
break;
default:
break;
}
Console.Read();
}
private static void AddEmployee(List<employee> list, employee ep)
{
Console.WriteLine("请输入要增加的员工信息:");
Console.Write("工号:");
ep.Number = Console.ReadLine();
Console.Write("姓名:");
ep.Name = Console.ReadLine();
Console.Write("性别:");
ep.Sex = Console.ReadLine();
Console.Write("生日:");
ep.Birthday = Console.ReadLine();
Console.Write("身份证号:");
ep.IdCard = Console.ReadLine();
Console.Write("学历:");
ep.Education = Console.ReadLine();
list.Add(ep);
Console.WriteLine("输入1继续增加员工信息;输入2查询员工信息;输入3返回主界面");
string b = Console.ReadLine();
switch (b)
{
case "1":
Console.WriteLine("请输入要增加的员工信息:");
Console.Write("工号:");
ep.Number = Console.ReadLine();
Console.Write("姓名:");
ep.Name = Console.ReadLine();
Console.Write("性别:");
ep.Sex = Console.ReadLine();
Console.Write("生日:");
ep.Birthday = Console.ReadLine();
Console.Write("身份证号:");
ep.IdCard = Console.ReadLine();
Console.Write("学历:");
ep.Education = Console.ReadLine();
list.Add(ep);
break;
case "2 ":
break;
case "3":
break;
default:
break;
}
} 展开
{
PrintMainMenu();
List<employee> list=new List<employee>();
employee ep = new employee();
string a = Console.ReadLine();
switch (a)
{
case "1":
AddEmployee(list, ep);
break;
case "2":
break ;
case "3":
break;
case "4":
break;
case "5":
break;
default:
break;
}
Console.Read();
}
private static void AddEmployee(List<employee> list, employee ep)
{
Console.WriteLine("请输入要增加的员工信息:");
Console.Write("工号:");
ep.Number = Console.ReadLine();
Console.Write("姓名:");
ep.Name = Console.ReadLine();
Console.Write("性别:");
ep.Sex = Console.ReadLine();
Console.Write("生日:");
ep.Birthday = Console.ReadLine();
Console.Write("身份证号:");
ep.IdCard = Console.ReadLine();
Console.Write("学历:");
ep.Education = Console.ReadLine();
list.Add(ep);
Console.WriteLine("输入1继续增加员工信息;输入2查询员工信息;输入3返回主界面");
string b = Console.ReadLine();
switch (b)
{
case "1":
Console.WriteLine("请输入要增加的员工信息:");
Console.Write("工号:");
ep.Number = Console.ReadLine();
Console.Write("姓名:");
ep.Name = Console.ReadLine();
Console.Write("性别:");
ep.Sex = Console.ReadLine();
Console.Write("生日:");
ep.Birthday = Console.ReadLine();
Console.Write("身份证号:");
ep.IdCard = Console.ReadLine();
Console.Write("学历:");
ep.Education = Console.ReadLine();
list.Add(ep);
break;
case "2 ":
break;
case "3":
break;
default:
break;
}
} 展开
2个回答
展开全部
没太明白你的意思,我猜你的意思是可以让用户不断地
输入1继续增加员工信息;输入2查询员工信息;输入3返回主界面
在主函数里写
string a = Console.ReadLine();
while(a!="Exit")
{
switch(a){...}
}
输入1继续增加员工信息;输入2查询员工信息;输入3返回主界面
在主函数里写
string a = Console.ReadLine();
while(a!="Exit")
{
switch(a){...}
}
追问
我是想让用户添加信息后可以选择回到主程序,再次选择需求,如查询啊什么的,这个应该怎么办
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用循环呀套住switch
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询