在控制台中清除一行 [英] Clearing a line in the console

查看:104
本文介绍了在控制台中清除一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中清除控制台中的一行?

How can a line in the console be cleared in C#?

我知道如何将光标置于行首:

I know how to place the cursor at the beginning of a line:

Console.SetCursorPosition(0, Console.CursorTop);

推荐答案

最简单的方法是像您所做的那样移动到行的开头,然后写出一个长度与线.

Simplest method would be to move to the start of the line, as you have done, and then write out a string of spaces the same length as the length of the line.

Console.Write(new String(' ', Console.BufferWidth));

这篇关于在控制台中清除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆