\ is a special character (sign) In C#. It is used for escape sequences(break out) such as to print a new line – we use \n, to print a tab – we use \t. We have to use a double backslash (\\) to print a backslash (\).
If we write \ within the message – it throws an error “Unrecognized escape sequence”.
Examples:
Input : \\
Geeksfor\\Geeks
Output : \
Geeksfor\Geeks
Input : Clean\\Evironment
Output: Clean\Evironment
Below is the implementation of the above approach:
Example 1:
// C# program to print backslash (\) using System; using System.IO; using System.Text; namespace geeks { class GFG { // Main Method static void Main(string[] args) { // to print "\" Console.WriteLine("\\"); // to print "\" between string Console.WriteLine("Geeksfor\\Geeks"); } } } |
Output:
\ Geeksfor\Geeks
Example 2:
// C# program to print backslash (\) using System; using System.Text; namespace geeks { class GFG { // Main Method static void Main(string[] args) { // to print "\" between string Console.WriteLine("Green\Clean"); } } } |
Error:
Unrecognized escape sequence `\C'
Example 3:
// C# program to print backslash (\) using System; using System.Text; namespace geeks { class GFG { // Main Method static void Main(string[] args) { // to print "\" between string Console.WriteLine("Clean\\Evironment"); // to print "\"n and "\"t Console.WriteLine("\\n\\t"); } } } |
Output:
Clean\Evironment \n\t
Recommended Posts:
- C# Program to print all permutations of a given string
- Program to print half Diamond star pattern
- Program to Print a New Line in C#
- Program to Input Weekday Number and Print the Weekday in C#
- Hello World Program : First program while learning Programming
- Different Ways to Take Input and Print a Float Value in C#
- Program to convert Byte array to IP Address
- C# Program for Naive algorithm for Pattern Searching
- C# Program for KMP Algorithm for Pattern Searching
- C# Program for Count Inversions in an array | Set 1 (Using Merge Sort)
- C# Program for Median of two sorted arrays of same size
- C# Program for Activity Selection Problem | Greedy Algo-1
- C# Program for Subset Sum Problem | DP-25
- C# Program for Dijkstra's shortest path algorithm | Greedy Algo-7
- C# Program for Maximum sum rectangle in a 2D matrix | DP-27
- C# Program for Largest Sum Contiguous Subarray
- C# Program for Maximum size square sub-matrix with all 1s
- C# Program for Minimum number of jumps to reach end
- C# Program for Cutting a Rod | DP-13
- C# Program for Longest Palindromic Subsequence | DP-12
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

