Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 清除当前行,就像C中的fflush(stdout)一样_C#_Console_Fflush - Fatal编程技术网

C# 清除当前行,就像C中的fflush(stdout)一样

C# 清除当前行,就像C中的fflush(stdout)一样,c#,console,fflush,C#,Console,Fflush,我有一个很长的for循环,它打印出许多行信息。我想把它保持在只覆盖前几行的一行。我尝试了Console.out.flush(),但它似乎不起作用。使用 Console.SetCursorPosition 获取光标使用的位置 Console.CursorLeft Console.CursorTop 范例 int i = 0; Console.WriteLine("Numbers will count below this line"); int cLeft = Console.Cursor

我有一个很长的for循环,它打印出许多行信息。我想把它保持在只覆盖前几行的一行。我尝试了Console.out.flush(),但它似乎不起作用。

使用

Console.SetCursorPosition
获取光标使用的位置

Console.CursorLeft
Console.CursorTop
范例

int i = 0;

Console.WriteLine("Numbers will count below this line");

int cLeft = Console.CursorLeft;
int cTop = Console.CursorTop;

while (true)
{
    Console.SetCursorPosition(cLeft, cTop);
    Console.WriteLine(i);
    i++;
}

很可能您正在寻找旁注:Yang,您可以链接到
fflush
方法的“刷新”行为的哪一部分吗?不是所有使用C的人都熟悉C运行时。。。还有关于“保持一行”的意思。你的意思是“代码>控制台。清除< /代码>或者?这些正是我正在寻找的。还不确定它是否是答案-考虑编辑职位,以澄清对你正在回答的问题的确切解释。请注意,我已经链接到了完全相同的建议-目前还不清楚OP在寻找什么,否则将是重复的。@AlexeiLevenkov既然OP已经接受了这个答案,我就说它是重复的。