Introduction to the. config file in c #

Source: Internet
Author: User

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"

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.