C#高级控制台I / O

我有多个I / O任务,我想用控制台做:

  • 打印出标准的,不可编辑的文本( Console.WriteLine()
  • 打印出用户可以编辑的文本( ?
  • 允许用户键入,并能够通过上述两种方法输出文本( ?
    • 如果我也能做密码屏蔽会很好。

有人有任何解决方案吗?

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

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

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

也许你可以尝试一下curses,有一个C#包装器可用。 虽然没有自己试过,但是……

像1988年的Mono’s getline一样派对。 http://tirania.org/blog/archive/2008/Aug-26.html

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

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