Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio Debugger remove \n in display?

I expected the debugger display of variable a in the following code to be {11\n22} it however is {1122}:

class A
{
    public string Text;
    public override string ToString()
    {
        return this.Text;
    }
}

A a = new A();
a.Text = "11\n22";

The debugger shows in the variables window:

display string of the object  "{1122}"    // why not "{11\n22}" ?
a.Text                        "11\n22"
a.ToString()                  "11\n22"

Tested with VS2012 and VS2010. I never realized this before. Anybody knows WHY the display string omits the \n character?

even adding [DebuggerDisplay("Text")] gives the same result.

like image 456
citykid Avatar asked Nov 17 '25 10:11

citykid


2 Answers

Try to pin it and you will be see what you need.

like image 105
Coding child Avatar answered Nov 20 '25 01:11

Coding child


It seems like Visual Studio is showing the Object.ToString() removing all the whitespaces.

But if you copy the text & paste it onto Notepad it shows the string with all the whitespaces.

Visual studio seems to designed/coded that way!

like image 42
Parimal Raj Avatar answered Nov 20 '25 00:11

Parimal Raj