C#清除控制台的最后一项并替换新项?控制台动画 [英] C# clear Console last Item and replace new? Console Animation

查看:47
本文介绍了C#清除控制台的最后一项并替换新项?控制台动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下CSharp代码(仅作为示例):

The following CSharp Code(just sample):

Console.WriteLine("Searching file in...");

foreach(var dir in DirList)
{
    Console.WriteLine(dir);
}

将输出打印为:

Searching file in...

dir1

dir2

dir3

dir4

.

.

.

问题?我怎么得到的输出为

Searching file in...

dir1  

(然后清除dir1并打印dir2等)所有下一个dir名称将替换上一个dir

(then clear dir1 and print dir2 and so on)All next dir name wiil replace the previous dir

推荐答案

如果您的问题是清除控制台,请使用方法 Console.Clear(); ,如果不是,请使用此方法覆盖最后一行;

If your problem is clearing the console then use the method Console.Clear();, if it's not, use this to overwrite the last line;

Console.WriteLine("Searching file in...");
        foreach(var dir in DirList)
         {
           Console.SetCursorPosition(1,0);
           Console.WriteLine(dir);
         }

这篇关于C#清除控制台的最后一项并替换新项?控制台动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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