【问题标题】:Looping through Properties.Settings using a string使用字符串循环遍历 Properties.Settings
【发布时间】:2016-07-30 11:05:07
【问题描述】:

有没有办法使用像下面这样的标识符来遍历设置

for (int i = 1; i < 6; i++)
{
    Properties.Settings.Default.["S" + i.ToString()]= 0;//identifier expected
}

替换这些:

Properties.Settings.Default.S1 = 0;
Properties.Settings.Default.S2 = 0;
Properties.Settings.Default.S3 = 0;
Properties.Settings.Default.S4 = 0;
Properties.Settings.Default.S5 = 0;

问题是它抛出 identifier expected 错误

【问题讨论】:

    标签: c# .net for-loop properties.settings


    【解决方案1】:

    像这样尝试,即删除点“。”在Default 之后调用索引操作符

    Properties.Settings.Default["S" + i.ToString()]= 0
    

    【讨论】:

    • :D np - 我相信你不是唯一一个有时会遇到简单错误的人(包括我!)
    猜你喜欢
    • 2015-02-13
    • 1970-01-01
    • 2021-04-02
    • 2014-02-28
    • 2014-09-19
    • 2023-03-23
    • 2016-01-24
    • 1970-01-01
    相关资源
    最近更新 更多