using App.cofig to Store value

As we know, In asp.net ,we can use web.config to store the configuration for the website.but In WinForm, we can use App.config to function the same function. See below settings:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="test" value="testwwwwwwwwww"/>
</appSettings>
</configuration>

We can use the following code to control the value:

using System;
using System.Windows.Forms;
using System.Configuration;

namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string value = ConfigurationSettings.AppSettings["test"];
MessageBox.Show(value);
}
}
}

Can you see, It's just so easy. so if you want to config the SQL server by configuration chars, you can put your connection strings here , and use the ConfigurationSettings.Appsettings[] method to read it.

 

你可能感兴趣的:(store)