-1

我发现问题
问题出在 MonoDevelop 上,它在控制台中运行良好。感谢您的帮助。

我正在使用 C# 控制台应用程序,并且我构建了一个简单的菜单,当要求用户输入时,它没有显示输入的第一个字符。

这是我的代码。

Console.Write("Input >");
string result = Console.ReadLine();
switch(result) {
     case "1":
          Console.WriteLine("1");
     break;
     case "2":
         Console.WriteLine("2");
     break;
     default:
         Console.WriteLine("Invalid");
     break;
}

--EDIT-- 实际代码

Console.Write("\t\t\t+");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("-----------------------------");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("+");

Console.Write("\t\t\t|");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("---MENU----------------------");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("|");

Console.Write("\t\t\t|");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("------|1|-HELP MENU----------");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("|");

Console.Write("\t\t\t|");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("------|2|-INITIATE CHAT------");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("|");

Console.Write("\t\t\t|");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("------|3|-CONFIGURATION -----");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("|");

Console.Write("\t\t\t+");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("-----------------------------");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("+");

Console.ForegroundColor = ConsoleColor.White;           
string result = Console.ReadLine();
menuInput(result);
4

1 回答 1

2

适合我

        Console.Write("\t\t\t+");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.Write("-----------------------------");
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("+");

        Console.Write("\t\t\t|");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("---MENU----------------------");
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("|");

        Console.Write("\t\t\t|");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("------|1|-HELP MENU----------");
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("|");

        Console.Write("\t\t\t|");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("------|2|-INITIATE CHAT------");
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("|");

        Console.Write("\t\t\t|");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("------|3|-CONFIGURATION -----");
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("|");

        Console.Write("\t\t\t+");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.Write("-----------------------------");
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("+");

        Console.ForegroundColor = ConsoleColor.White;

        Console.Write("Input >");
        string result = Console.ReadLine();
        switch (result)
        {
            case "1":
                Console.WriteLine("1");
                break;
            case "2":
                Console.WriteLine("2");
                break;
            default:
                Console.WriteLine("Invalid");
                break;
        }

        Console.ReadLine();

在此处输入图像描述

于 2012-04-22T15:03:53.680 回答