Successfully added
...see more
We can also use the \
escape character to store the string He said "Hi"
inside a string variable in C#. We would have to write a \
before each double quote like He said \"Hi\"
. The following code example shows us how we can escape double quotes with the \
escape character in C#.
string msg = "He said \"Hi\""; Console.WriteLine(msg);
Output:
He said "Hi"
We saved the string msg
with the value He said "Hi"
by using the \
escape character in C#.
...see more
C# defines the following character escape sequences:
- \' - single quote, needed for character literals
- \" - double quote, needed for string literals
- \\ - backslash
- \0 – Null
- \a - Alert
- \b - Backspace
- \f - Form feed
- \n - New line
- \r - Carriage return
- \t - Horizontal tab
- \v - Vertical quote
- \u - Unicode escape sequence for character
- \U - Unicode escape sequence for surrogate pairs.
- \x - Unicode escape sequence similar to "\u" except with variable length.
Referenced in:
Comments