Shanxx
Posted on November 26, 2023
Character Escape Sequence
- An escape character sequence is an instruction to the runtime to insert a special character that will affect the output of your string. In C#, the escape character sequence begins with a backslash \ followed by the character you're escaping.
\
- use case -> Console.WriteLine("Hello \"World\"!");
-> Hello "World"!
-> backslash \
followed by the character you're escaping
\n
- new line
\t
- new tab big space
Verbatim string literal
- will keep all whitespace and characters without the need to escape the backslash.
Console.WriteLine(@" c:\source\repos
(this is where your code goes)");
Output
c:\source\repos
(this is where your code goes)
Unicode escape characters
- add encoded characters in literal strings using the \u escape sequence, then a four-character code representing some character in Unicode (UTF-16).
Console.WriteLine("\u3053\u3093\u306B\u3061\u306F World!");
Output -> // Kon'nichiwa World
String Interpolation
int version = 11;
string updateText = "Update to Windows";
Console.WriteLine($"{updateText} {version}!");
Outpt:
Update to Windows 11!
💖 💪 🙅 🚩
Shanxx
Posted on November 26, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.