Martin Georgiev Martin Georgiev -4 years ago 93
C# Question

How to recognize this character "\" in C#

I just want to write in Console this "\".

Console.Write("\");


But it doesn't recognize it like a string or character ,but as a command.

Answer Source

\ is used as an escape character inside strings. In order to output the \ itself you need to escape it by doubling it up, or use a string literal by prefixing your string with @.

Either of these will work.

Console.WriteLine("\\");

Console.WriteLine(@"\");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download