我想知道是否有可能在运行程序时执行特定的代码段(程序是命令行界面)。C#执行特定代码
程序按顺序执行所有操作,但这不是我想要的。
下面是两个程序运行的截图以及它背后的代码。
[]
// Read all the bookings between dates:
Console.WriteLine("Input start date in the format yyyy-mm-dd");
DateTime bookingStartDate = DateTime.Parse(Console.ReadLine());
Console.WriteLine("Input end date in the format yyyy-mm-dd");
DateTime bookingEndDate = DateTime.Parse(Console.ReadLine());
DbBookings bookings = new DbBookings(bookingStartDate, bookingEndDate);
foreach (DbBooking booking in bookings.Bookings)
{
Console.WriteLine("booking start date = " + booking.startDate);
Console.WriteLine("booking end date = " + booking.endDate);
Console.WriteLine("booking room No = " + booking.roomNo);
Console.WriteLine("booking guest = " + booking.guestName);
Console.WriteLine("booking guest phone No = " + booking.guestPhone);
Console.WriteLine("booking cost = " + booking.cost);
}
//Create a new booking
Console.WriteLine("Bed and breakfast create new booking");
Console.WriteLine("Input start date in the format yyyy-mm-dd");
DateTime startDate = DateTime.Parse(Console.ReadLine());
Console.WriteLine("Input end date in the format yyyy-mm-dd");
DateTime endDate = DateTime.Parse(Console.ReadLine());
Console.WriteLine("What room?");
int room = int.Parse(Console.ReadLine());
Console.WriteLine("Customer Name");
string name = Console.ReadLine();
Console.WriteLine("Customer phone number");
string phone = Console.ReadLine();
double cost = (endDate.ToOADate() - startDate.ToOADate()) * 29;
DbBooking newBooking = new DbBooking(
startDate,
startDate,
room,
name,
phone,
cost
);
Console.ReadLine();
我想要什么程序做的是要问两个问题,“你想阅读的预约”和“你要添加新的预订”你会回答这些通过输入'1'或'2'来输入问题
[这个答案](https://stackoverflow.com/a/11141262/5174469)应该给你如何创建这样的接口 –
测试参数计算正确的开始。如果为零,则从ReadLine()获取输入。如果大于零,则从args数组中获取值。使用:args.Count() – jdweng
不要发布代码的图片,将代码复制到问题中,然后突出显示该代码,并在代码在预览窗口中显示格式不正确的情况下按下“{}”工具栏按钮。 –