zoukankan      html  css  js  c++  java
  • C# AppSettings

    目标:学会读取配置文件中的AppSettings

    ①在App.config中追加AppSettings。AppSettings是键值对,注意定义位置在<configuration></configuration>中

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
      <appSettings>
        <add key = "name" value = "张三" />
        <add key = "age" value = "10" />
      </appSettings>
    </configuration>

    ②在References中追加System.Configuration

    ③取值

    String value = ConfigurationManager.AppSettings["KeyName"];

    using System;
    using System.Configuration;
    
    
    public static void Test()
    {
        String name = ConfigurationManager.AppSettings["name"];
        int age = Convert.ToInt32(ConfigurationManager.AppSettings["age"]);
        Console.WriteLine("name:"+name);
        Console.WriteLine("age:" + age);
    }
     
  • 相关阅读:
    问题排查
    代码
    前端
    即时通信系统 偶尔看到 就想学着做一下
    Oracle 笔记
    javaweb dev 入
    mysql安装
    windows下安装nginx
    spring MVC上传附件
    mysql+mybatis递归调用
  • 原文地址:https://www.cnblogs.com/wyvern0618/p/9454129.html
Copyright © 2011-2022 走看看