想弄一个函数从配置文件里读取值
App.config
<?xml version="1.0" encoding="utf-8" ?><configuration>
<!--实时数据存储系统初始化需要的参数--> <appSettings> <add key="pointCount" value="7"/> <add key="maxOffset" value="0.005"/> <add key="timerInterval" value="5000"/> <add key="bufferLength" value="20"/> <add key="readInterval" value="1500"/> <add key="storePath" value="c:\\"/> </appSettings></configuration>
函数
private static string GetAppConfig(string strKey)
{
foreach (string key in ConfigurationManager.AppSettings)
{
if (key == strKey)
{ return ConfigurationManager.AppSettings[strKey]; }
}
return null;
}
怎么弄也不成功,各位大牛帮我看看啊
App.config
<?xml version="1.0" encoding="utf-8" ?><configuration>
<!--实时数据存储系统初始化需要的参数--> <appSettings> <add key="pointCount" value="7"/> <add key="maxOffset" value="0.005"/> <add key="timerInterval" value="5000"/> <add key="bufferLength" value="20"/> <add key="readInterval" value="1500"/> <add key="storePath" value="c:\\"/> </appSettings></configuration>
函数
private static string GetAppConfig(string strKey)
{
foreach (string key in ConfigurationManager.AppSettings)
{
if (key == strKey)
{ return ConfigurationManager.AppSettings[strKey]; }
}
return null;
}
怎么弄也不成功,各位大牛帮我看看啊
doc.Load(filename);
XmlNode node = doc.SelectSingleNode("//appSettings");
XmlElement element = (XmlElement)node.SelectSingleNode("//add[@key='" + appKey + "']");if (element != null)
{
value = element.GetAttribute("value");
}System.Configuration.ConfigurationManager.AppSettings[""]);