C# 使用app.config文件方法 读取外部配置信息
一、app.config
该文件是应用程序配置文件,可以使用用于
ConfigurationManager类,读取数据;
二、例
app.config文件
<?xml version="1.0"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> <connectionStrings> <add name="dbConStr" connectionString="Server=localhost;Database=simple_ter_network;UserID=root;Password=root"/> </connectionStrings> </configuration>
C#文件部分源码
using System.Configuration;
string connectStr = ConfigurationManager.ConnectionStrings["dbConStr"].ConnectionString; MessageBox.Show(connectStr);