StringCollection in application settings doesn't get stored

痴心易碎 提交于 2019-12-06 03:55:14

I found the solution by myself, the problem is that if you create your StringCollection with "new" keyword and save settings, they don't get stored.

The way to fix this is to "force" the application settings designer to create it for you, how to do it? Well it's quite easy, put stringcollection as type and insert 2/3 strings. Press ok. Then edit again this value and remove all strings to leave it "created but empty".

After this, you can just use it by adding/removing strings and save settings. And you will be sure it won't be null!

Application settings can be scoped at the application level and at the user level and you can only write to settings at the user level, so if you have a StringCollection scoped at the application level you can only read the values that you defined at compile time and adding to the collection at runtime will have no effect the next time you start your application.

You can scope it at the user level if you want changes to propagate between application runs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!