Search⌘ K
AI Features

Formatting Methods to Output

Explore different methods to format output in C# console applications, including writing text without line breaks, using numbered positional arguments, and applying string interpolation. Understand format strings for numbers and currency, and practice aligning text and numbers for better console display.

Console apps are text-based and are run at the command line. They typically perform simple tasks that need to be scripted, such as compiling a file or encrypting a configuration file section. Equally, they can have arguments passed to control their behavior.

An example of this would be to create a new console app using the F# language with a specified name instead of using the name of the current folder, as shown in the following command line:

Shell
dotnet new console -lang "F#" --name "ExploringConsole"

Displaying output to the user

The two most common tasks that a console app performs are:

  • Writing data

  • Reading data

We have already been using the WriteLine method to output, but if we didn’t want a carriage return at the end of a line, for example, if we later wanted to continue to write more text to the end of that line, we could ...