我想知道当我在下一行的开头时是否有可能回到最后一行?(当然是在C#Console中)
我的意思是Console.WriteLine()因为进入下一行,即使按下回车后我也想留在我的行中.(我认为没有另一种方法可以在不进入下一行的情况下使用ReadLine,是吗?)
我发现这Console.SetCursorPosition()可能很有用,如下所示:
int x, y;
Console.WriteLine("Please enter the point's coordinates in this form (x,y):");
Console.Write("(");
x = Convert.ToInt32(Console.ReadLine());
Console.SetCursorPosition(x.ToString().Length + 1, Console.CursorTop - 1);
Console.Write(",");
y = Convert.ToInt32(Console.ReadLine());
Console.SetCursorPosition(x.ToString().Length + y.ToString().Length + 2, Console.CursorTop - 1);
Console.WriteLine(")");
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常,但当我试图改变Console.Write("("); 在某些事情上Console.Write("Point A=("),我需要Console.SetCursorPosition()每次更改参数.
如果我可以将光标移动到控制台缓冲区中的最后一个字符(空格除外),那将非常有用.(我认为如果我可以将一个特定的行从控制台复制到字符串中会很容易.)
提前致谢.