9.7. The string type and string literals

There are two types of string literals in C#:

  • regular string literals;

  • verbatim string literals.

What we have seen and used so far are regular string literals. These consist of characters enclosed in double quotation marks and may contain escape sequences, hexadecimal (\x) and Unicode (\u) escape sequences within. Examples of regular string literals include the following:

  • "Hello!"

  • "My \tname is\nMok"

  • "Apple starts with the letter \u0041, Banana starts with the letter \x42"

Verbatim string literals are string literals which are 'what they seem'. If you include a @ sign in front of a string literal, everything between the double quotes will be considered part of the string 'as they are'. The @ symbol, in this ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.