zoukankan      html  css  js  c++  java
  • 在控制台程序中,添加config文件

    一、右击类库 → 添加 → 新建项 → 应用程序配置文件(或者选择一个XML文件,然后将名字改成XXX.config),内容如下:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="constr" value="0"></add>
      </appSettings>
    </configuration>
     
    二、控制台程序中使用配置文件中的值
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Configuration;//添加System.Configuration.dll的引用
    using System.Collections.Specialized;
    namespace test
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = System.Configuration.ConfigurationManager.AppSettings.Get("constr");
                Console.WriteLine(str);
                NameValueCollection sall = ConfigurationManager.AppSettings;
                foreach (string s in sall.Keys)
                {
                    Console.WriteLine(s+":"+sall.Get(s));
                }
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    一个Electron的设计缺陷及应对方案
    如何点击穿透Electron不规则窗体的透明区域
    Electron团队为什么要干掉remote模块
    Clickhouse 单机双实例
    Kafka安全认证SASL/PLAIN
    Syslog的使用
    Kafka Consumer
    Kafka Producer客户端
    Kafka客户端操作
    springboot集成flyway实践
  • 原文地址:https://www.cnblogs.com/vichin/p/7116643.html
Copyright © 2011-2022 走看看