我这里有一种输入星期几的方法,但是如果我输入的数字值不是1到7,则程序会简单地得出结论。我想有一种方法来触发捕获。 namespace DaysOfTheWeek{class Program{ public enum EDay { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, } static void Main(string[] args) { try { Console.WriteLine("Hello! A week has 7 days! What day of this week is it?"); EDay pickDay = (EDay)Enum.Parse(typeof(EDay), Console.ReadLine(), true); Console.WriteLine("The day you picked was {0}", pickDay - 1); Console.ReadLine(); } catch (Exception) { Console.WriteLine("Please enter an actual numerical day of the week."); Console.ReadLine(); } }}}
3 回答
- 3 回答
- 0 关注
- 132 浏览
添加回答
举报
0/150
提交
取消