C#高级控制台输入输出

4
我有多个I/O任务需要在控制台中完成:
  • 打印标准的不可编辑文本(Console.WriteLine()
  • 打印用户可以编辑的文本(
  • 允许用户输入,并能够通过上述两种方法输出文本(

有人有解决方案吗?

4个回答

5

2
也许你可以尝试使用咒语,有一个 C# 封装 可用。虽然我自己没有尝试过...

2

0

答案已经提交,但以下代码可能会有所帮助

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
    public static int i = 0;
    public static string[] S = new string[] { "A", "B", "C", "D", "E", "F" };
    static void Main(string[] args)
    {

        Console.Write("Please Select : "+S[i]);
        ConsoleKeyInfo K = Console.ReadKey(); 
        while (K.Key.ToString() != "Enter")
        {
            Console.Write(ShowOptions(K));
            K = Console.ReadKey();
        }
        Console.WriteLine("");
        Console.WriteLine("Option Selected : " + S[i]);

        Console.ReadKey();
        }
    public static string ShowOptions(ConsoleKeyInfo Key)
    {

        if(Key.Key.ToString() == "UpArrow")
        {
            if (i != S.Length-1)
                return "\b\b" + S[++i];
            else 
                return "\b\b" + S[i];
        }
        else if (Key.Key.ToString() == "DownArrow")
        {
            if(i!=0)
            return "\b\b" + S[--i];
            else 
                return "\b\b" + S[i];
        }

        return "";
    }
}

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接