C#如何读取config配置文件数据?

 

String hotelname = ConfigurationManager.AppSettings["hotelname"];
需要在资源管理器的引用里面,添加System.Configuration,然后再在代码中添加 using System.Configuration;
才能使用。
.net 3.0以后,均需要引用 System.Configuration 才能访问配置文件。

 

第一步,在右侧的资源管理器里,引用,添加引用,选择.net中的System.Configuration
第二步,在代码最前面,添加using System.Configuration;
第三步,在你想读取配置文件的地方,使用
String hotelname = ConfigurationManager.AppSettings["hotelname"];
变量hotelname读取的就是配置文件中你添加的值了

posted @ 2014-05-06 16:11  xian.luo  阅读(586)  评论(0编辑  收藏  举报