Boris Eetgerink

June 22, 2023

From 0 to 100% on a single line

Or how to display a progress indicator in a console app:

// Avoid a blinking cursor.
Console.CursorVisible = false;

Console.WriteLine("Downloading...");
for (int i = 0; i <= 100; i++) {
    // Overwrite the output on the current line.
    Console.CursorLeft = 0;
    Console.Write($"Progress: {i.ToString(),3}%");
    await Task.Delay(50);
}

// Terminate the progress line.
Console.WriteLine();
Console.WriteLine("Download complete.");

Output:

Downloading...
Progress: 100%
Download complete.

That's all!

About Boris Eetgerink

Hey, thanks for reading my blog. Subscribe below for future posts like this one and check my personal site in order to contact me.