小编Ali*_*Ali的帖子

C#控制台 - 如何在没有新行的情况下读取线条()?(或撤消\n或垂直\ b)

我想知道当我在下一行的开头时是否有可能回到最后一行?(当然是在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()每次更改参数.

如果我可以将光标移动到控制台缓冲区中的最后一个字符(空格除外),那将非常有用.(我认为如果我可以将一个特定的行从控制台复制到字符串中会很容易.)

提前致谢.

c# console newline edit console.readline

1
推荐指数
1
解决办法
2939
查看次数

标签 统计

c# ×1

console ×1

console.readline ×1

edit ×1

newline ×1