We are all familiar with the differences between global variables and local variables. global variables have a global scope and can work in all functions on a page. A local variable has a local scope and only takes effect in the function of the currently defined variable. However, if a variable is used in the entire project, the commonly defined global variables and local variables will become ineffective. At this time, configuring a variable in config will play a role in macro and local variables, it is convenient to use in the entire project.
The configuration and reading are simple and practical.
Add reference
Using system. configuration;
//Configuration variables in config:<Connectionstrings> <Add name ="Test"Connectionstring ="0"/>//Variable name, the default value of the variable. You can define the variable as needed.</Connectionstrings>
Read variable:
//Get the variable value in configIf(Configurationmanager. connectionstrings ["Test"]! =Null){IntTest = convert. toint32 (configurationmanager. connectionstrings ["Test"]. Connectionstring. tostring (). Trim ());}