最简单
namespace ProcessStu01
{
internal class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 100; i++)
{
Console.Write("\r{0,3}%",i);
Thread.Sleep(50);
}
}
}
}
第三方库
https://github.com/Mpdreamz/shellprogressbar
using ShellProgressBar;
namespace ProcessStu01
{
internal class Program
{
static void Main(string[] args)
{
Console.ReadKey();
const int totalTicks = 100;
var options = new ProgressBarOptions
{
ForegroundColor = ConsoleColor.Yellow,
ForegroundColorDone = ConsoleColor.DarkGreen,
BackgroundColor = ConsoleColor.DarkGray,
BackgroundCharacter = '\u2593'
};
using (var pbar = new ProgressBar(totalTicks, "showing off styling", options))
{
for (int i = 0; i < totalTicks; i++)
{
pbar.Tick();
Thread.Sleep(100);
}
}
Console.ReadKey();
}
}
}