Recently I learned the. config file in c # and made some notes on what I learned:
Some people may have doubts about the function of learning the. config file. What help does it provide to us in actual work?
Let's first look at the AppConfig function:
Its important function is to unify command line options and configuration file options into a data structure so that you can set parameters externally without modifying the code to achieve the desired effect, this may confuse you. Let's look at the following example:
Create an App. config file with the following content:
In this App. config defines only one parameter key as "TestURL", and its value is "http: // cspauthoringppe/zh-/news/_ layouts/user. aspx"
Now, how can we get the value of "TestURL" through c # code?
The Code is as follows:
You can use this line of code to obtain the value set in App. config. Here, the value set in App. config is assigned to the string testURL,
Therefore, the string testURL is "http: // cspauthoringppe/zh-/news/_ layouts/user. aspx"
It is worth noting that the ConfigurationManager method is in the namespace using System. Configuration. If this namespace is not added, the ConfigurationManager method cannot be obtained.
I just want to talk about it here. In fact, there are many things in it. If you want to explore it, you can find relevant books. Finally, I will give you a sentence.
"Without a long journey or even a thousand miles, without a small flow, it cannot become a sea of rivers and seas"