我有多个I/O任务需要在控制台中完成:
- 打印标准的不可编辑文本(
Console.WriteLine()
) - 打印用户可以编辑的文本(
?
) - 允许用户输入,并能够通过上述两种方法输出文本(
?
)- 如果我能做密码屏蔽就更好了。
有人有解决方案吗?
如何在控制台文本编辑器中编辑文本?
我认为你所需要的一切都在Console类中,可以查看它的成员:
答案已经提交,但以下代码可能会有所帮助
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 "";
}
}
}