C#读写config配置文件的方法

2019-12-30 15:03:20刘景俊

测试代码如下:


class Program
  {
    static void Main(string[] args)
    {
      try
      {
        //string file = System.Windows.Forms.Application.ExecutablePath + ".config";
        //string file1 = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
        string serverIP = ConfigHelper.GetAppConfig("ServerIP");
        string db = ConfigHelper.GetAppConfig("DataBase");
        string user = ConfigHelper.GetAppConfig("user");
        string password = ConfigHelper.GetAppConfig("password");

        Console.WriteLine(serverIP);
        Console.WriteLine(db);
        Console.WriteLine(user);
        Console.WriteLine(password);

        ConfigHelper.UpdateAppConfig("ServerIP", "192.168.1.11");
        string newIP = ConfigHelper.GetAppConfig("ServerIP");
        Console.WriteLine(newIP);

        Console.ReadKey();
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
    }
  }

以上这篇C#读写config配置文件的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持ASPKU。


注:相关教程知识阅读请移步到c#教程频道。