ConfigurationManager.AppSettings in returning null

后端 未结 4 1952
猫巷女王i
猫巷女王i 2020-12-16 15:26

I am using ConfigurationManager.AppSettings[myKey] to read a value from the app.config file in my windows application, but the value returned is always null, even though the

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 16:33

    One, perhaps easier, alternative is to use a Settings file. This encapsulates the creation and maintenance of App.config values in a designer GUI and generates code for accessing the values.

    To add a Settings file, right click your project in VS and click 'Add -> New Item', select 'Settings file' and give it a meaningful name, e.g. MainSettings.settings. You can then add an item, e.g. Foo, specify whether it is application or user-wide, define it's type and a assign it a value. In your code you can retreive the value by simple writing MainSettings.Default.Foo.

    After compilation, you can change the value by editing the config file. The setting will appear as follows:-

    
        
            
                Bar
            
        
    
    

提交回复
热议问题