【问题标题】:C# Advanced Console I/O [duplicate]C# 高级控制台 I/O [重复]
【发布时间】:2011-06-20 16:26:15
【问题描述】:

我有多个 I/O 任务要使用控制台执行:

  • 打印出标准的、不可编辑的文本 (Console.WriteLine())
  • 打印出用户可以编辑的文本 (?)
  • 允许用户输入,并能够通过上述两种方法输出文本(?

有人有解决办法吗?

【问题讨论】:

    标签: c# console io


    【解决方案1】:

    也许你可以试试 curses,有一个 C# wrapper 可用。不过自己没试过……

    【讨论】:

      【解决方案2】:

      像在基于控制台的文本编辑器中一样编辑文本?

      我认为您所需要的只是在 Console 类中,看看它的成员:

      http://msdn.microsoft.com/en-us/library/system.console.aspx

      【讨论】:

        【解决方案3】:

        派对就像是 1988 年 Mono 的 getline。 http://tirania.org/blog/archive/2008/Aug-26.html

        【讨论】:

          【解决方案4】:

          答案已提交 但下面的代码可能会有所帮助

          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 "";
              }
          }
          
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2023-03-17
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-12-18
            • 2020-06-25
            • 2012-06-02
            相关资源
            最近更新 更多