源地址
http://gb2013.blog.163.com/blog/static/21735301201021253713453/
View Code
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="student" type="System.Configuration.DictionarySectionHandler"/> </configSections> <student> <add key="name" value="amily"/> <add key="age" value="15"/> <add key="sex" value="female"/> </student> </configuration>
注意事项:configSections 相当于定义变量,必须放在configuration
IDictionary istudent = (IDictionary)ConfigurationManager.GetSection("student"); string[] keys=new string[istudent.Keys.Count]; string[] values = new string[istudent.Keys.Count]; istudent.Keys.CopyTo(keys,0); istudent.Values.CopyTo(values, 0); foreach (var key in keys) { Console.WriteLine(key); } foreach (var value in values) { Console.WriteLine(value); } foreach (var key in istudent.Keys) { Console.WriteLine("{0}:{1}", key, istudent[key]); }