Formatting Methods to Output
Learn about console applications in C#, including string formatting and optimizartion.
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:
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 have used the Write
method.
Formatting using numbered positional arguments
One way of generating formatted strings is to use numbered positional ...