マルチレベルconfigSections

4942 ワード

ソースアドレス
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は定義変数に相当し、configrationに置かなければならない.
           
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]);

            }