InterviewSolution
| 1. |
What Is A Verbatim String Literal And Why Do We Use It? |
|
Answer» 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"; string MultiLineText = @"This is multiline Text written to be in three lines."; string DoubleQuotesString = @"My Name is ""Vankat."""; 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"; string MultiLineText = @"This is multiline Text written to be in three lines."; string DoubleQuotesString = @"My Name is ""Vankat."""; |
|