4

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

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121

1 Answers1

4

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.

John Leidegren
  • 59,920
  • 20
  • 131
  • 152
  • This is not my experience (visual studio 2010, .NET 4) – Matt Ellen Mar 21 '11 at 18:20
  • 1
    I think Matt is right - I retyped the line of code and it gave me a different result, which made me realize the bell character had gotten hidden in the string by the ReSharper refactor... I should also say "thanks" for making me think about the fact that the \a was a bell char :) – Aaron Anodide Mar 21 '11 at 19:09