多层次configSections

源地址

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]);
            }
复制代码

 

 

posted on   雨渐渐  阅读(273)  评论(0编辑  收藏  举报

导航

点击右上角即可分享
微信分享提示