Reading and writing to configuration files in. NET 2.0
Source: Internet
Author: User
In the. NET 2.0-based Enterprise Library, the original configuration Application block was abolished and the. NET 2.0 self-read and write configuration features were used, so let's take a look at the features of read and write configuration in. NET 2.0. namely: ConfigurationManager class
Note: ConfigurationManager is the preferred method of handling client application configuration files, and any other method is not recommended.
For WEB applications, it is recommended that you use the WebConfigurationManager class.
The AppSettings property of this class is available at the time of the previous 1.0, and the connectionstrings attribute is added to 2.0.
None of this is what we're going to discuss today, what we're going to discuss today is to save a configuration class to a configuration file and instantiate the configuration class from the configuration file.
This configuration class must be derived from the System.Configuration.ConfigurationSection class
As the following class is a configuration class
Using System.Text;
Using System.Configuration;
Namespace Configtest
{
Class Configdataclass:configurationsection
{
Public Configdataclass ()
{ }
[ConfigurationProperty ("id")]
public int id{
Get{return (int) this["id"];
set{this["id" = value;}
}
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