Q:

C# program to print backslash (\\)

belongs to collection: C# Basic Programs | basics

0

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 (\\).

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the example of New keywo... >>
<< C# program to print a new line...