我正在尝试从我的 C# 文件中的 App.config 引用一个变量。这是我的代码示例。
App.config:
<appSettings>
<add key="ErrorEmails" value="fakeCompany@fakeCompany.com"/>
</appSettings>
代码:
SettingsIO setIO = new SettingsIO();
public static string To = setIO.ReadSetting("ErrorEmails");
错误如下:
A field initializer cannot reference the non-static field, method, or preperty 'test.setIO'.
我应该使用 GET 函数吗?我做错了什么?
请您参考如下方法:
使用 system.configuration 类。
string str = System.Configuration.ConfigurationManager
.AppSettings["someAppSetting"]
.ToString();
