【发布时间】:2011-06-20 16:26:15
【问题描述】:
我有多个 I/O 任务要使用控制台执行:
- 打印出标准的、不可编辑的文本 (
Console.WriteLine()) - 打印出用户可以编辑的文本 (
?) - 允许用户输入,并能够通过上述两种方法输出文本(
?)- 如果我也能password masking 就好了。
有人有解决办法吗?
【问题讨论】:
我有多个 I/O 任务要使用控制台执行:
Console.WriteLine())?)?)
有人有解决办法吗?
【问题讨论】:
也许你可以试试 curses,有一个 C# wrapper 可用。不过自己没试过……
【讨论】:
像在基于控制台的文本编辑器中一样编辑文本?
我认为您所需要的只是在 Console 类中,看看它的成员:
【讨论】:
派对就像是 1988 年 Mono 的 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 "";
}
}
}
【讨论】: