Fir*_*DoL 3 c# string collections application-settings
我想使用StringCollection作为应用程序设置,但是在阅读它不是问题时,我发现没有存储设置.
如何使其工作?任何解决方法?这有什么问题?
我正在使用的代码:
private static void AddToRecentProfiles(string path)
{
if (SpellCaster3.Properties.Settings.Default.RecentProfiles == null)
SpellCaster3.Properties.Settings.Default.RecentProfiles = new StringCollection();
int index = SpellCaster3.Properties.Settings.Default.RecentProfiles.IndexOf(path);
if (index >= 0)
SpellCaster3.Properties.Settings.Default.RecentProfiles.Swap(index, 0);
else
SpellCaster3.Properties.Settings.Default.RecentProfiles.Insert(0, path);
if (SpellCaster3.Properties.Settings.Default.RecentProfiles.Count > SpellCaster3.Properties.Settings.Default.MaxRecentProfiles)
SpellCaster3.Properties.Settings.Default.RecentProfiles.RemoveAt(SpellCaster3.Properties.Settings.Default.RecentProfiles.Count - 1);
SpellCaster3.Properties.Settings.Default.Save();
OnRecentProfilesChanged(SpellCaster3.Properties.Settings.Default.RecentProfiles, EventArgs.Empty);
}
Run Code Online (Sandbox Code Playgroud)
Fir*_*DoL 10
我自己找到了解决方案,问题是如果使用"new"关键字创建StringCollection并保存设置,则不会存储它们.
修复此问题的方法是"强制"应用程序设置设计器为您创建它,如何做到这一点?好吧,这很简单,把stringcollection作为类型并插入2/3字符串.按确定.然后再次编辑此值并删除所有字符串以使其"创建但为空".
在此之后,您可以通过添加/删除字符串并保存设置来使用它.你肯定它不会是空的!
| 归档时间: |
|
| 查看次数: |
5286 次 |
| 最近记录: |