Escape Sequences & Verbatim Literal

Escape Sequences & Verbatim Literal
Rating: 5 - 1 Votes

Escape Sequences & Verbatim Literal

C#A character which is a combination of a backslash (\) followed by another character or a letter is known as Escape Sequence.  There are numerous escape sequences provided by Microsoft.  For example:  If you want to have a new line after certain string or character, you can simply use \n to have a new line.  You can get the list of available escape sequences from HERE.  Because there are certain characters which has been reserved for specific use, we make use of escape sequences to print those characters.

Please see the code given above.   If you will try to run this code, you will get an error because there are double quotes and quote is a reserved character.   If in this code, we want to print the quotes with Hello, World!, then we have to make use of escape sequence character, which is backslash (\).

The above given code will work fine with the help of escape sequence character.  But if the string is lengthy and it will contain nearly 20 reserved characters then using backslash (\) after every character will make your code look dirty plus a lot of confusing.  In that case, you can make use of verbatim literal.  For using verbatim literal, you just need to put @ character before that string.  Please see the code given below about the usage.

The output will be same as we had after using backslash (\).