Core C#

Printing Special Characters

This C# program demonstrates how to print special characters via the console window. The special characters that we print are the newline, the carriage return, the horizontal tab, the backslash, and the alert bell. Each of these are designated by a character preceded by a backslash. The newline skips to the next line. The carriage return moves the beginning of the current line; for this reason, the words Carriage return are overwritten. The tab adds whitespace. The backslash just prints a backslash, but it requires a preceding blackslash because it is used singly to designate special characters. The bell character makes a bell noise.

Program.cs

using System;

namespace XoaX {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine("Newline \n - Skip to the next line.");
            Console.WriteLine("Carriage return \r - Return to the start of this line.");
            Console.WriteLine("Tab \t - Skip a few characters of whitespace.");
            Console.WriteLine("Backslash \\ - Print a backslash.");
            Console.WriteLine("Alert bell \a - Make a bell sound.");
        }
    }
}
 

Output

Newline
 - Skip to the next line.
 - Return to the start of this line.
Tab      - Skip a few characters of whitespace.
Backslash \ - Print a backslash.
Alert bell  - Make a bell sound.
Press any key to continue . . .
 
 

© 2007–2024 XoaX.net LLC. All rights reserved.