why is this verbatim string not working as I expect for a unit test assert and showing a strange value in debugger?

653 Views Asked by At

enter image description here

QUESTION: Why does the debugger show "directagents\a\aanodide" instead of the value of the verbatim string @"directagents\aanodide".

UPDATE This seems to be a ReSharper quirk. To Reproduce:

  1. Enter a literal string with a "\a" in it.
  2. Apply the refactor "Change to Verbatim Sring"
    • "\a" becomes invisible in th verbatim string
    • "\a" is not really gone.

More evidence from immediate window showing Hand Typed VS. Copy/Paste. enter image description here

1

There are 1 best solutions below

2
John Leidegren On

The debugger doesn't know that you use the compiler verbatim style to create the string. It just displays the string using the most common representation which isn't verbatim.

A verbatim string, besides accepting new line, also doesn't recognizes escape sequences so \a which is a bell character ends up as two characters in one case and as one character when not using the verbatim style.

You can lookup the reference for C# string literals here.