7 Things about C#: Console I/O

Joe Mayo
Seven Things about C#
8 min readJun 27, 2023

--

A terminal station — like a train or airplane terminal.

The console is the command line, where you type commands to run code and get a response. In general terms, input and output (I/O) describe the interactions of information being given to the program (input) and information that the program emits.

These interactions are often communication with a user, but can also be communication with other programs. We won’t get that elaborate here, but will describe some interesting I/O capabilities that you can use in a C# application to communicate with people.

1 — There are different ways to write

The Console class has two writing methods: Write and WriteLine. The difference is that WriteLine adds a new line after printing and Write doesn’t. Here’s an example:

Console.WriteLine("Console I/O Demo\n");

Console.WriteLine("\t 1. Door #1");
Console.WriteLine("\t 2. Door #2");
Console.WriteLine("\t Q. Quit");

Console.Write("\nYour Choice (1, 2, or Q): ");

You’ve seen Console.WriteLine in the previous post on Running Apps. However, there are a few differences here, specifically in the strings with escape, \, characters, which are special instructions to the terminal. The first line contains a newline escape, \n, which adds a line in the terminal where it appears. This example has the effect of adding two newlines because one is…

--

--

Joe Mayo
Seven Things about C#

Author, Instructor, & Independent Consultant. Author of C# Cookbook: — http://bit.ly/CSharpCookbook — @OReillyMedia #ai #csharp #Web3