Is there a replacement for config.ini for C#?
I want to create a config.ini
that exist in Java for C#?
Is there a way?
I discovered I have to create an App.config
file.
But after creating the App.config
, how do I use C# to read the add key?
This App.config
is mainly for dynamic file path.
For general application settings, you would store them in the <appSettings>
element:
<appSettings>
<add key="MySetting" value="Hello World" />
</appSettings>
You can then read the settings using the ConfigurationManager
or WebConfigurationManager
class, e.g.:
string mySettings = ConfigurationManager.AppSettings["MySetting"];
For non-web projects, add a reference to System.Configuration.dll
To your project, add reference to System.Configuration assembly then use such code to read the value of specific appSetting
from the config based on its key:
string value = System.Configuration.ConfigurationManager.AppSettings["key"];
ConfigurationManager.AppSettings["settigs1"] = "value1";
Please, try search answer for you question in Google or Bing like this
精彩评论