我使用enum作为switch语句的选项,并且它可以工作。问题是如果用户输入一个无效的选项程序崩溃。我应该添加什么,以便使用默认值?使用enum和switch语句c#
我枚举类
public enum Options : byte
{
Display = 1,
Add,
Toggle,
Max,
Mean,
Medium,
Exit
}
在枚举程序崩溃主我switch语句
string volString = Console.ReadLine();
Options options = (Options)Enum.Parse(typeof(Options), volString);
// this is the line that is giving me the runtime error. Since other options are not found
。
switch (options)
{
case Options.Display: //dispaly regular time
case Options.Toggle://toggle
default:
Console.WriteLine("entry blah blah");
break;
你会得到什么样的运行时错误的? – dasblinkenlight 2012-01-08 00:12:01