• 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);
    }
     
  • 相关阅读:
    CVPR顶会热词统计
    @Annotation学习
    把一张表已有的数据对另一张表数据进行修改
    两张表数据不一致进行对比
    学习借鉴
    借鉴tcp
    借鉴tcp
    osi七层
    http学习
    Json学习
  • 原文地址:https://www.cnblogs.com/wyvern0618/p/9454129.html
Copyright © 2020-2023  润新知