• ConfigurationManager


    ConfigurationManager读取和写入

     
      提供对客户端应用程序配置文件的访问
      通过引入System.Configuration.dll可以用ConfigurationManager类来读取项目中保存在App.config中的配置信息,如:
     
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="Number0" value="9759436"/>
        <add key="Number1" value="9759437"/>
        <add key="Number2" value="9759438"/>
        <add key="Number3" value="9759439"/>
      </appSettings>
        <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>
    </configuration>
     
     
    后台:
     
    读取数据:  
    private void Button_Click_1(object sender, RoutedEventArgs e)
     {
            int i = int.Parse(ConfigurationManager.AppSettings["Number2"]);
            this.txtMsg.Text = i.ToString();
     }

     

    写入数据: 
    Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    cfa.AppSettings.Settings["Number2"].Value = "65434";
    cfa.Save();
     
  • 相关阅读:
    Python 标准库 urllib2 的使用细节
    为什么C++编译器不能支持对模板的分离式编译
    source insight插件
    tar命令
    绘制和重绘,有效矩形和无效矩形
    常量表达式
    区间迭代
    lambda函数
    decltype和新的返回值语法
    auto用法
  • 原文地址:https://www.cnblogs.com/infly123/p/3759611.html
Copyright © 2020-2023  润新知