C#如何遍历Properties.Settings.Default.Properties更改值 [英] C# How to loop through Properties.Settings.Default.Properties changing the values

查看:494
本文介绍了C#如何遍历Properties.Settings.Default.Properties更改值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

foreach (SettingsProperty currentProperty in Properties.Settings.Default.Properties)
{
    if (Double.TryParse(GenerateValue()), out result))
    {
        currentProperty.DefaultValue = result.ToString();

        Properties.Settings.Default.Save();
    }
}

它从mysql数据库获取新值。如果我添加一个MessageBox.Show来显示新值,则似乎工作正常,但实际上并没有保存它。我认为这是因为我正在将值分配给变量...是否有某种方法可以做到这一点?

It gets the new value from a mysql database. If I add a MessageBox.Show to show the new value it seems to be working fine but it doesn't actually save it. I assume this is because I am assigning the value to a variable...is there some way to do this?

Properties.Settings.Default.IndexOf(currentProperty.name).DefaultValue = result


推荐答案

这可能起作用:

foreach (SettingsProperty  currentProperty in Properties.Settings.Default.Properties)
{
    Properties.Settings.Default[currentProperty.Name] = result.ToString();
    Properties.Settings.Default.Save();
}

请记住,属性应具有范围 User才能保存

Keep in mind that properties should have scope 'User' in order to be saved.

这篇关于C#如何遍历Properties.Settings.Default.Properties更改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆