Program to Print Backslash () in C#

\ 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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");
    }
}
}

chevron_right


Output:

\
Geeksfor\Geeks

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");
    }
}
}

chevron_right


Error:

Unrecognized escape sequence `\C'

Example 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");
    }
}
}

chevron_right


Output:

Clean\Evironment
\n\t



My Personal Notes arrow_drop_up


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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.