【发布时间】:2020-10-14 13:15:41
【问题描述】:
首先我要稍微解释一下我的程序!
我编写了一个邮件投递程序,它允许用户开始投递包裹并保存发件人姓名和发件人目的地等值,然后列出包裹,然后开始投递包裹。
这里我有一个名为 senderDestination 的公共类,我将值保存到列表中。
public class senderDestination
{
public string senderName { get; set; }
public string destination { get; set; }
public string delivered;
public string pending;
public string delivering;
public senderDestination(string status, string pendingStatus, string startingDelivery)
{
delivered = status;
pending = pendingStatus;
delivering = startingDelivery;
}
}
这里有一个 switch 语句,在这个 switch 语句中,我允许用户输入值,例如交货目的地名称和我们要发送给的人的姓名:
case ConsoleKey.D2:
Clear();
bool registeringSenderAndDestination = true;
do
{
senderDestination senderdestination = new senderDestination("Delivered", "Pending Delivery", "Starting Delivery");
Write("Sender: ");
senderdestination.senderName = ReadLine();
Write("Destination: ");
senderdestination.destination = ReadLine();
Clear();
WriteLine($"Sender: {senderdestination.senderName}");
WriteLine($"Destination: {senderdestination.destination}");
allSenders.Add(senderdestination);
} while (registeringSenderAndDestination);
Clear();
break;
在我的第三个 switch case 语句中,我允许用户列出我们刚刚保存的所有包:
case ConsoleKey.D3:
Clear();
int id = 1;
WriteLine("ID Destination Status");
WriteLine("------------------------------------------------------------------");
// List packages
foreach (var sender in allSenders)
{
// write here all the information you want to display.
WriteLine($"{id++} {sender.destination,-14} {sender.pending}");
}
ReadKey(true);
Clear();
break;
第四个 switch 语句是用户想要开始交付这些包裹时单击的位置:
case ConsoleKey.D4:
Clear();
int ids = 1;
WriteLine("Starting delivery on pending packages...");
WriteLine("------------------------------------------------------------------");
WriteLine("ID Destination Status");
WriteLine("------------------------------------------------------------------");
foreach (var sender in allSenders)
{
WriteLine($"{ids++} {sender.destination,-14} {sender.delivering}");
}
Thread.Sleep(4000);
Clear();
break;
我想要做的是当用户单击菜单中的第四个 switch 语句时,我希望第三个 switch 语句从 {sender.pending} 更改为 {sender.delivered} 但我不知道该怎么做.我还能做到吗?对不起,如果我在这个问题中有很多代码,我不知道如何解释它。
【问题讨论】:
标签: c#