我正在尝试使用Console.ReadKey()在C#中创建一个基本上基于用户按下的键(例如X = Quit,D = Disconnect等;)的函数; 在c#中
我遇到的问题是如何在Switch语句中使用ReadKey信息..有人可以帮忙吗?代码如下.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Switch_Test
{
class Program
{
static void Main()
{
Console.WriteLine("Welcome. Please enter your command: ");
string chinput;
int input;
bool activated = false;
input = Console.ReadKey();
chinput = Convert.ToChar(input);
switch (chinput)
{
case 'x':
{
Console.WriteLine("You pressed x...");
break;
}
case 'y':
{
Console.WriteLine("You pressed y..");
break;
}
case 'd':
{
if (activated != true)
{
Console.WriteLine("Please activate first!");
break;
}
else
{
Console.WriteLine("Active.."); …Run Code Online (Sandbox Code Playgroud)