+6  A: 

The dictionary isn't doing anything to your string. The debugger, or more specifically the expression evaluator, will alter the format of a displayed string when it contains newline characters. The end goal is to make it display better on the single line the debugger typically has for values.

I recently did a blog post which goes into detail about what the debugger does and the reason behind the design

EDIT

I believe there is a bug in your sample code. I think you left at @ symbol off of the value in the add of the Dictionary. Without the @ symbol I do not get your repro but with it I do. Assuming the @ is missing though ...

The reason why you see the string with extra escapes is that the debugger always displays strings as string literals and not verbatim strings. In a string literal you need the double escape to match the equivalent code in the verbatim string. Hence \n becomes \\n

JaredPar
Thanks, but I'm not entirely convinced. My problem is that I don't want the extra slashes added to my newline characters.
JohnB
@JohnB, Added some more context to explain why double slashes would appear.
JaredPar
I am not using @"" - I do understand that @ escapes special characters for you. I will do more testing later, I have to leave now. Thanks.
JohnB
@JaredPar: how come I see "\\r\\n" when I hover over `value`?
JohnB
@JohnB, if the `\\` are showing then the `\` character is being inserted directly into the string and is not a part of an escape sequence. I've tried the posted repro a Visual Studio 2010 and don't see the behavior unless I make it a verbatim string.
JaredPar
@JohnB: edits invalidated my comment; deleted.
tenfour
+2  A: 

If you are reading the string from the app.config, I assume it's something like the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="errorString" value="An error occured.\r\nPlease try again later."/>
  </appSettings>
</configuration>

In which case your sample code should look like this:

keyValuePairs.Add("1", @"An error occured.\r\nPlease try again later.");

And from there it should be obvious why the debugger is displaying as it does (especially if you read JaredPar's answer.

You're better off using a resource dictionary for storing the string, which will easily let you insert newline characters in the VS editor.

Edit: Just on a whim, I tried the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="errorString" value="An error occured.
Please try again later."/>
  </appSettings>
</configuration>

Compiled fine and produced the correct results.

Giraffe
@Giraffe, absolutely correct on both questions: #1 that reading from App.config (AKA XML file) is equivalent to `@""` because it implicitly escapes the `"\"` character, #2 simply typing a carriage return into the App.config fixes my problem. Thanks. *(JaredPar's answer had nothing to do with my question.)*
JohnB
Also, JaredPar is correct to. The debugger displays `value1` with `"\\r\\n"` which is the actual value after it gets read in from the App.config. However, the debugger displays the `Dictionary` contents by hiding the extra slashes: `"\r\n"`
JohnB