应用程序配置文件(.config)

1.首先要添加引用:System.Configuration

2.using System.Configuration;和using System.Collections;

3.在App.config文件中添加以下信息



  
    
4.在main()函数中添加以下代码显示读取配置文件信息:
String ConnectionStrings = ConfigurationManager.ConnectionStrings["BillModelContainer"].ToString();
Console.WriteLine("ConnectionStrings:{0}", ConnectionStrings);

IDictionary dict = ConfigurationManager.GetSection("userinfo") as IDictionary;
foreach (var key in dict.Keys)   //遍历
{
    Console.WriteLine("key:{0} value:{1}", key, dict[key]);
}
String IPInfo = ConfigurationManager.AppSettings["IPInfo"];
Console.WriteLine("IP:{0}", IPInfo);
Console.ReadLine();

输出结果: 应用程序配置文件(.config)_第1张图片
个人订阅号: 应用程序配置文件(.config)_第2张图片



你可能感兴趣的:(.Net)