C#訪問應(yīng)用程序配置文件的方法
更新時間:2013年03月21日 11:12:12 作者:
C#訪問應(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>
在控制臺應(yīng)用程序中訪問,代碼如下:
首先添加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)文章
C#實現(xiàn)打開畫圖的同時載入圖片、最大化顯示畫圖窗體的方法
這篇文章主要介紹了C#實現(xiàn)打開畫圖的同時載入圖片、最大化顯示畫圖窗體的方法,涉及C#針對窗體及圖片操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08C# 關(guān)于爬取網(wǎng)站數(shù)據(jù)遇到csrf-token的分析與解決
這篇文章主要介紹了C# 關(guān)于爬取網(wǎng)站數(shù)據(jù)遇到csrf-token的分析與解決,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下2021-01-01