Why is \ character being doubled in my @ string?

The visual studio debugger will show it as if it were doubled, since in C# a \ would precede an escape sequence. Don't worry - your string is unchanged.


It only looks like it's doubled in the debug inspectors.

Note that the strings shown in the inspectors don't start with @ - they are showing how you would have to write the string if you were to do it without the @. The two forms are equivalent.

If you're really worried about the contents of the string, output it in a console app.


To reiterate in another way, the comparison

var equal = @"^\+(?:[0-9] ?){6,14}[0-9]$" == "^\\+(?:[0-9] ?){6,14}[0-9]$"

will always be true. As would,

var equal = @"\" == "\\";

If you examine the variables using the Text Visualizer, you will be shown the plain unescaped string, as it was when you declared it verbatim.