共计 568 个字符,预计需要花费 2 分钟才能阅读完成。
using System;
using System.Threading;
class Program
{static void Main()
{Console.WriteLine("正在安装...");
int totalProgress = 50; // 进度条的总长度
for (int i = 0; i <= totalProgress; i++)
{DrawProgressBar(i, totalProgress);
Thread.Sleep(100); // 模拟一些任务正在进行
}
Console.WriteLine("\n 安装完成!");
Console.ReadLine();}
static void DrawProgressBar(int progress, int total)
{Console.Write("\r"); // 光标移动到行首
int barLength = 30;
int filledLength = (int)(((double)progress / total) * barLength);
string progressBar = "[" + new string('#', filledLength) + new string('-', barLength - filledLength) + "]";
Console.Write(progressBar + $"{progress * 100 / total}%");
}
}
正文完