为什么我的标签忽略来自 App.config 文件的新行(“\n”)?

Ric*_* L. 4 .net c# winforms

所以我有一个 App.config 文件设置如下:

<configuration>
    <appSettings>
        <add key="Description" value="My too long of a\n description that needs\n new lines so the entire\n thing can be seen."/>
    </appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

现在,在运行时,我需要将Texta 的属性更改Label为 App.config 文件中的众多描述之一。如果我在 App.config 中包含新行字符,Label似乎会忽略它是一个新行字符,而是按字面打印出来。但是,如果我要删除这些新行字符并在运行时插入它们,那么系统Label将识别它们并按应有的方式插入新行。

我的问题是,为什么?Label如果它们来自 App.config,为什么会忽略它们并逐字打印它们?

要使用 App.config 中的描述,我要做的就是:

myLabel.Text = ConfigurationManager.AppSettings["Description"];
Run Code Online (Sandbox Code Playgroud)

Joe*_*Joe 5

我期望\r\n在 Windows 系统上 (return, newline),而不仅仅是换行符。无论如何,App.config 是 XML,因此您需要 XML 转义序列:

&#xD;&#xA;
Run Code Online (Sandbox Code Playgroud)