Home » C# » C# programs » C# basic 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?
Submitted by IncludeHelp, on April 07, 2019

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.