During developmentProgramSuch as the file path and database link.
Use the following method in winform:
1. Create a configuration file:
In Solution Explorer, right-click the project name and choose add> new item> application configuration file;
The default name is app. config.
2. Modify the app. Con File
1:
XML version =" 1.0" encoding =" UTF-8 "? >
2: Configuration >
3: appsettings >
4: Add key =" username " value =" sa " />
5: Add key =" PWD " value =" Sasa " />
6: Add key =" servername " value =" Kay-PC " />
7: Add key =" dbname " value =" pubs " />
8: appsettings >
9: </Configuration>
The key is the name and the value is the key value.
3. Use the configuration file
For testing, put a button on the form to bring up the value of the key corresponding to the value.
1: // Add a namespace
2: UsingSystem. configuration;
3: ......
4: private void button2_click ( Object sender, eventargs e)
5:{
6:// Input the key name in the receivettings.
7:MessageBox. Show (configurationsettings. receivettings ["Username"]. Tostring ());
8:}