C# App.config 自定义 配置节

(1)App.config



 
   


   

   

 
 
   
   
   
 

 
   
 

 

对于自定义的配置节,应该先在 中声明要配置的节与类型,如着色部分,接着,在后面定义要配置的具体内容,正如定义一个变量。

 (2)配置节的访问

       public static void Main(string[] args)
        {
            //get color
            NameValueCollection color = (NameValueCollection)ConfigurationManager.GetSection("color");
            foreach (String str in color.AllKeys) {
                Console.WriteLine(str+":"+color[str]);
            }
            //get message
            IDictionary message = (IDictionary)ConfigurationManager.GetSection("message");
            foreach (String str in message.Keys) {
                Console.WriteLine(str+":"+message[str]);
            }
            // get name
            IDictionary name = (IDictionary)ConfigurationManager.GetSection("name");
            foreach (String str in name.Keys)
            {
                Console.WriteLine(str + ":" + name[str]);
            }   
            //Console.WriteLine(name["firstName"]);
            Console.Read();
        }


转载于:https://www.cnblogs.com/zengle_love/archive/2009/03/22/1419138.html

你可能感兴趣的:(C# App.config 自定义 配置节)