Which of the following two methods can be used to read node configuration values in the web. config file faster?

Source: Internet
Author: User

<Deleetask>
<Add key = "DSN" value = "provider = Microsoft. Jet. oledb.4.0; Data Source = c: \ Inetpub \ wwwroot \ data. mdb"/>
<Add key = "my1" value = "119"/>
</Appsettings>

1. Method 1
String constring1 = system. configuration. configurationsettings. deleettings ["DSN"];

This method uses the configurationsettings. deleettings attribute (static attribute)
This is also the most commonly used method.

2. Method 2
System. configuration. appsettingsreader appreader = new system. configuration. etettingsreader ();
String constring2 = convert. tostring (appreader. getvalue ("my1", typeof (string )));

This method first creates an instance of the appsettingsreader class, and then obtains the value of the configured node using the instance method getvalue.

How fast is the two methods?
Method 1 is simple and clear in writing.
Method 2 is slightly more written. I personally think that if you read the values of multiple configuration points at a time, you can consider method 2.
Method 1 uses static attributes, and IL converts static attributes to static attributes.

 

 

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.