c# - 切换到默认大小写
问题描述
我不明白为什么我的开关盒不起作用。我试图从转换为 Int32 的 Console.Read 变量中获取用户输入,但开关直接跳转到默认情况。
主要方法:
class Program {
static void Main(string[] args) {
Console.WriteLine("##############################################");
Console.WriteLine("# #");
Console.WriteLine("# 1 - ADD ITEM 3 - VIEW ITEMS #");
Console.WriteLine("# 2 - EDIT ITEM 4 - DELETE ITEM #");
Console.WriteLine("# #");
Console.WriteLine("##############################################");
// Get input from user
int userChoice = Convert.ToInt32(Console.Read());
// Call function that responds to user selection from main menu
Functions function = new Functions();
function.SelectFunction(userChoice);
}
}
这是从一个名为 Functions 的类中获取的 switch 方法:
public void SelectFunction(int choice) {
switch (choice) {
case 1:
Console.WriteLine("ADD ITEM");
/*Console.WriteLine("Please enter ID:");
var id = Console.ReadLine();
Console.Write("Item name: ");
var name = Console.ReadLine();*/
break;
case 2:
Console.WriteLine("EDIT ITEM");
break;
case 3:
Console.WriteLine("VIEW ITEMS");
break;
case 4:
Console.WriteLine("DELETE ITEM");
break;
default:
Console.WriteLine("Input not found in any of the choices. Please try again.");
Console.ReadKey();
break;
}
}
解决方案
推荐阅读
- angular - 如何修复订阅泄漏 Angular ngrx 商店
- angular - 未找到自定义管道 ionic 4 | 找不到管道
- android - 即使我的过程是正确的,也无法解决 github 依赖关系
- firebase - Firebase Cloud Functions:无法从文件中读取凭据
- c# - 如何停止数据表 RowFilter 动态更新
- javascript - 标签不活动时如何防止无限滚动加载页面?
- php - 致命错误:未捕获的错误:在 C:\xampp\htdocs\code\project\routes\web.php:18 中找不到类 'Route'
- python - For循环计数器不递增
- python - WindowsPath 无法转换为 unicode
- java - 我想恢复每个字符串的值