简体   繁体   中英

StringCollection changes on Settings.Default.Reload()

In my app Settings.Default.test is a StringCollection . I don't understand why this code

    StringCollection col = new StringCollection();
    col.Add("1\r\n2\r\n");
    Settings.Default.test = col;
    Settings.Default.Save();
    Settings.Default.Reload();

Changes my text 1\\r\\n2\\r\\n to 1\\n2\\n on Reload. Is it default behavior or what? How to restore multiline text in my textbox on restart of my application?

When the data is saved to the user.config settings it will look like this: (c:\\users[username]\\appdata\\local[appname]..\\user.config)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <userSettings>
        <EmptyObjects.Properties.Settings>
            <setting name="Setting" serializeAs="Xml">
                <value>
                    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <string>1
2
</string>
                    </ArrayOfString>
                </value>
            </setting>
        </EmptyObjects.Properties.Settings>
    </userSettings>
</configuration>

The data is serialized to XML then deserialized to string(s). If you need to preserve the information you can:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM