zoukankan      html  css  js  c++  java
  • C#如何在控制台应用程序中加入配置文件

    C#如何在控制台应用程序中加入配置文件

    一、在控制台程序中加入xml文档命名为App.config(记住一定要起这个名字,否则不能访问)文件的内容如下:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="key0" value="0"></add>
        <add key="key1" value="1"></add>
        <add key="key2" value="2"></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
    {
        //注意一定要记住配置文件的名称为App.config
        class Program
        {
            static void Main(string[] args)
            {
                string str = ConfigurationManager.AppSettings.Get("key0");
                Console.WriteLine(str);
                NameValueCollection sall = ConfigurationManager.AppSettings;
                foreach (string s in sall.Keys)
                {
                    Console.WriteLine(s+":"+sall.Get(s));
                }
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    Selenium之编辑框操作
    Selenium之勾选框操作
    Selenium之单选框操作
    [复习资料]组合计数学习笔记
    ARC104游记
    [被踩计划] 题解 [省选联考 2020 A 卷] 作业题
    题解 [SEERC2019]Game on a Tree
    [被踩计划] 题解 [NOI2020]美食家
    [被踩计划] 题解 [省选联考 2020 A 卷] 组合数问题
    [被踩计划] 题解 括号树
  • 原文地址:https://www.cnblogs.com/xiaofeilong/p/3396383.html
Copyright © 2011-2022 走看看