欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#訪問(wèn)應(yīng)用程序配置文件的方法

 更新時(shí)間:2013年03月21日 11:12:12   作者:  
C#訪問(wèn)應(yīng)用程序配置文件的方法,需要的朋友可以參考一下

App.config中寫(注意C#中的應(yīng)用程序配置文件名不能修改)

復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="URL" connectionString="http://www.hao123.com"/>
    <add name="IP" connectionString="192.168.1.107"/>
  </connectionStrings>

  <appSettings>
    <add key="con" value="http://localhost/web"/>
  </appSettings>
</configuration>


 

在控制臺(tái)應(yīng)用程序中訪問(wèn),代碼如下:

首先添加System.configuration.dll引用

然后引入命名空間 :using System.Configuration;

復(fù)制代碼 代碼如下:

 string conString = ConfigurationManager.AppSettings["con"];
 Console.WriteLine(conString);         
  string url = ConfigurationManager.ConnectionStrings["URL"].ConnectionString;
  Console.Write(url);

相關(guān)文章

最新評(píng)論