Verbatim string literals

Verbatim string literal does not require the use of escape characters to define special characters. Instead, any information in the source code, including new lines, is included in the string. To define a string literal an @ symbol is placed before the opening quotation mark. Verbatim string literals are often used for specifying paths and multi-line string.

Example code:

string path = @"C:\Program  Files\My Program";        //verbatim literal

string path2 = "C:\\Program  Files\\My Program";      //regular  literal

string msg = @"Hello,
This is a multi-line string";        //verbatim literal

string msg2 = "Hello,\nThis  is multi-line string";   //regular  literal

The only character that requires a different action is the quotation mark itself, which must be entered twice to indicate a single character.

, , ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Share to Facebook Share to Twitter Stumble It Share on Tumblr Digg More...