C# C循环使我的应用程序无法正常工作
我有一个应用程序,我用C写的只是为了练习,这是代码C# C循环使我的应用程序无法正常工作,c#,loops,switch-statement,C#,Loops,Switch Statement,我有一个应用程序,我用C写的只是为了练习,这是代码 using System; namespace Stock_Control { class Program { static void Main(string[] args) { int qty, index; string name, location, code; Item item = new Item(); ConsoleKeyInfo opt
using System;
namespace Stock_Control
{
class Program
{
static void Main(string[] args)
{
int qty, index;
string name, location, code;
Item item = new Item();
ConsoleKeyInfo opt;
do
{
Console.Clear();
Console.WriteLine();
Console.WriteLine("******************** STOCK CONTROL SOFTWARE *********************");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Chose a option:");
Console.WriteLine("1 - Add item.");
Console.WriteLine("2 - View Stock.");
Console.WriteLine("3 - Remove item.");
Console.WriteLine("4 - Press 'Escape' to exit.");
opt = Console.ReadKey(true);
switch (opt.KeyChar.ToString())
{
case "1":
Console.WriteLine();
Console.Write("Enter the item code:");
code = Console.ReadLine();
Console.Write("Enter the item quantity:");
qty = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the item name:");
name = Console.ReadLine();
Console.Write("Enter the item location:");
location = Console.ReadLine();
item.add(code, qty, name, location);
break;
case "2":
Console.WriteLine("teste");
//item.view();
break;
case "3":
Console.WriteLine();
Console.WriteLine("Enter the index of the item to be removed:");
index = Int32.Parse(Console.ReadLine());
item.remove(index);
break;
}
} while (opt.Key != ConsoleKey.Escape);
}
}
}
它工作得很好,但由于某种原因,当我绕过一个循环时,switch语句中的第二种情况就停止工作了,一旦我删除了这个循环,一切都正常了。我不知道出了什么问题
有人能帮我吗
谢谢。它仍然可以正常工作,但是当你添加循环时,你就可以使用你的控制台了;项目视图;在案例2中,然后立即重新启动=清除控制台,使您看不到任何东西 您能否提供有问题的代码而不是粘贴箱。请将代码放在此处您只读取一个键:opt=Console.ReadKeytrue;。opt也包含返回。因此,第二次通过循环,您读取的是返回值,而不是键入的键。