Home »
.Net »
C# Programs
C# program to print backslash (\)
Printing a backslash (\) in C#: Here, we are going to learn how to print a backslash (\) in C# after the message, between the message and anywhere else?
By IncludeHelp Last updated : April 15, 2023
C# printing a backslash (\)
In C#, \ is a special character (sign) – that is used for escape sequences like to print a new line – we use \n, to print a tab – we use \t etc.
In this case, if we write \ within the message – it will throw an error "Unrecognized escape sequence".
To print a backslash (\), we have to use a double backslash (\\).
C# code to print a backslash
In the below example – we are printing backslash, \n, \t etc
// C# program to print backslash (\)
using System;
using System.IO;
using System.Text;
namespace IncludeHelp {
class Test {
// Main Method
static void Main(string[] args) {
// printing "\"
Console.WriteLine("\\");
// printing between string "\"
Console.WriteLine("Hello\\World");
// printing "\"n and "\"t
Console.WriteLine("\\n\\t");
//hit ENTER to exit the program
Console.ReadLine();
}
}
}
Output
\
Hello\World
\n\t
C# Basic Programs »