Skip to content
Related Articles

Related Articles

Improve Article

Program to Print Backslash () in C#

  • Last Updated : 03 Aug, 2021

\ 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\\Environment
Output: Clean\Environment

Below is the implementation of the above approach:

Example 1: 



C#




// 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#




// 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#




// 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\\Environment");
 
        // to print "\"n and "\"t
        Console.WriteLine("\\n\\t");
    }
}
}

Output: 

Clean\Environment
\n\t

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :