Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
In C#, an escape sequence refers to a combination of characters beginning with a back slash (\) followed by letters or digits. Escape sequences represent non-printable and special characters in character and literal strings. As such, they allow users to communicate with a display device or printer by sending non-graphical control characters to specify actions like question marks and carriage returns.
An escape sequence is used when writing sections of code, like preprocessor definitions, to specify continuation characters, so that multiple lines of code are considered as a single line by the compiler. Regular expressions that help perform sophisticated string search operations use escape sequences to locate substrings within a large string. By enabling quoted strings, escape sequences may be used to create output files containing text template tags and files.
An escape sequence contains more than one character but functions as a single character because there is no letter to textually represent the escaped character. The compiler converts the sequence of characters into a single escaped character in the compiled program. For example, the compiler converts \n in the source code into a single character (code 10), which represents the line feed in the compiled program.
The following is a list of defined C# escape sequences with corresponding representations: