ConfigurationManager.AppSettings计数为0

时间:2017-05-17 21:00:39

标签: c#-4.0 configurationmanager

C# - ConfigurationManager.AppSettings计数为0.还有想法?这是代码:

  var appSettings = ConfigurationManager.AppSettings;

                    if (appSettings.Count == 0)
                    {
                        Console.WriteLine("AppSettings is empty.");
                    }

在调试中运行。 VS将app.config复制到调试目录并为其命名 CBCuedERI.exe.config。这是配置文件的一部分

<applicationSettings>
    <CBCuedERI.Properties.Settings>
        <setting name="test" serializeAs="String">
            <value>one</value>
        </setting>
    </CBCuedERI.Properties.Settings>
</applicationSettings>

我也尝试了这个,它返回NULL

  string sss = ConfigurationManager.AppSettings.Get ( "test") ;

1 个答案:

答案 0 :(得分:0)

ConfigurationManager.AppSettings用于appSettings部分中的键值对

Reading settings from app.config or web.config in .net