下面附上代码。我正在编写一个菜单,用户输入一个数字来选择一个菜单选项。它也包含在一个while循环中,因此用户可以一遍又一遍地重复菜单。它在第一个循环中完美运行,但在第二个循环中它给出“输入字符串格式不正确”。在 Console.ReadLine()
static void Main(string[] args)
{
bool again = true;
while (again)
{
string yourName = "Someone";
Console.WriteLine("\t1: Basic Hello, World.\n" +
"\t2: Calculate demoninations for a given value of change.\n" +
"\t3: Calculate properties of shapes.\n" +
"Please Select an Option: ");
int option = int.Parse(Console.ReadLine());//errors out here.
switch (option)
{
}
Console.Write("Press y to back to the main menu. Press any other key to quit: ");
char againChoice = (char)Console.Read();
if (againChoice == 'y')
{ again = true; }
else
{ again = false; }
}
Console.Write("Hit Enter to end");
Console.Read();
}