Friday, January 13, 2017

Verbatim string literal in C#


The "@" symbol is the verbatim string literal. 

Use verbatim strings for convenience and better readability when the string text contains backslash characters, for example in file paths. 

Because verbatim strings preserve new line characters as part of the string text, they can be used to initialize multiline strings. 

Use double quotation marks to embed a quotation mark inside a verbatim string. 

The following example shows some common uses for verbatim strings:


string ImagePath = @"C:\Images\Buttons\SaveButton.jpg";
Output: C:\Images\Buttons\SaveButton.jpg



string MultiLineText = @"This is multiline
Text written to be in
three lines.";

/* Output:
This is multiline
Text written to be in
three lines.
*/

string DoubleQuotesString = @"My Name is ""Prakash.""";
Output: My Name is "Prakash."

No comments:

Post a Comment