1. Configuration files
<?XML version= "1.0" encoding= "Utf-8"?><Configuration> <configsections> < Sectionname= "Color"type= "System.Configuration.NameValueSectionHandler" /> < Sectionname= "message"type= "System.Configuration.DictionarySectionHandler"/> < Sectionname= "Name"type= "System.Configuration.SingleTagSectionHandler"/> </configsections> <Color> <AddKey= "Red"value= "#ff0000"/> <AddKey= "Green"value= "#00ff00"/> <AddKey= "Blue"value= "#0000ff"/> </Color> <message> <AddKey= "Welcome"value= "Hello, welcome"/> </message> <nameFirstName= "Chen"LastName= "Plainly"/></Configuration>
2. Code Read
1 //Get Color2NameValueCollection color = (NameValueCollection) configurationmanager.getsection ("Color");3 foreach(String strinchcolor. AllKeys)4 {5Console.WriteLine (str +":"+color[str]);6 }7 //Get Message8IDictionary message = (IDictionary) configurationmanager.getsection ("message");9 foreach(String strinchmessage. Keys)Ten { OneConsole.WriteLine (str +":"+message[str]); A } - //Get name -IDictionary name = (IDictionary) configurationmanager.getsection ("name"); the foreach(String strinchname. Keys) - { -Console.WriteLine (str +":"+name[str]); - } + //Console.WriteLine (name["FirstName"]); -Console.read ();
C # custom config file