[英]How To Add/Remove Items in c# Console Application Menu
I'm wondering if I could use a few simple dictionaries to store the data behind this or if I need something more... Need a system to be able to add and remove items and have that translated to other menus (methods). 我想知道我是否可以使用一些简单的字典来存储背后的数据,还是我需要更多...需要一个能够添加和删除项目并将其转换为其他菜单(方法)的系统。 Sorry if this is worded poorly
对不起,如果措辞不好
public int AddProducts(int customerIDinput)
{
//If the order already has 5 products then display an error that no more products can be added
//Prompts the user for a product ID
//If the user selects an invalid product then display an error
//If the user selects a product that is discontinued then display an error
//Prompt the user for a quantity
//If the user enters a value < 1 or > 100 then display an error
//Add the product and quantity to the order
//Display the updated order information
//Return to the main menu
int input;
input = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please eneter a product ID:");
switch (customerIDinput)
{
case 1
break;
case 2
break;
case 3
break;
case 4
break;
case 5
break;
}
return customerIDinput;
}
You can use a generic List and switch the value entered by the user to be the INDEX
Value of that list of products 您可以使用通用列表并将用户输入的值切换为该产品列表的
INDEX
值
a quick Example : 一个简单的例子:
List<String> Products = new List<string>();
int Value = Int.Parse(Console.ReadLine());
switch(Value)
{
case 1:
if (Products.Item(1) == null)
Console.WriteLine("Doesnt Exist!"); // This check will be in all cases in the Default one of caus
break;
}
Or you can use that check in the first for example : 或者您可以在第一个示例中使用该检查:
List<String> Products = new List<string>();
int Value = Int.Parse(Console.ReadLine());
if (Products.Items(Value) == null)
{
//Display Error
}
else
{
switch(Value)
{
case 1:
//what u want here
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.