控制台应用程序
App.config:
AppSettings.config:
Program.cs:
string a = ConfigurationManager.AppSettings["a"]; string b = ConfigurationManager.AppSettings["b"]; Console.WriteLine("a={0}", a); Console.WriteLine("b={0}", b); Console.ReadKey();
报错:
解决方法:
重新运行结果:
web应用程序
Web.config:
AppSettings.config:
index.aspx.cs代码:
string a = ConfigurationManager.AppSettings["a"]; string b = ConfigurationManager.AppSettings["b"]; divTxt.InnerHtml += "a=" + a+ "<br/>b=" + b;
结果: