zoukankan      html  css  js  c++  java
  • visual C# 2005 express beta2读配置文件的问题(ms的bug?)

    visual C# 2005 express beta2读配置文件的问题:

    app.config
    -----------------------------------------------------------------------------------

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>
     
    <configSections>
      
    <sectionGroup name="mySectionGroup">
       
    <section name="mySection"
          type
    ="System.Configuration.DictionarySectionHandler" />
      
    </sectionGroup>
     
    </configSections>
     
    <mySectionGroup>
      
    <mySection>
       
    <add key="key1" value="value1" />
      
    </mySection>
     
    </mySectionGroup>
    </configuration>


    读取配置文件的程序(在项目中需要手动添加System.configuration的引用):
    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Collections.Specialized;
    using System.Configuration;

    namespace ConsoleApplication2
    {
        
    class Program
        
    {
            
    static void Main(string[] args)
            
    {
                
    try
                
    {
                    NameValueCollection ns 
    = (NameValueCollection)ConfigurationManager.GetSection("mySectionGroup/mySection");
                    
    string s = ns["key1"];
                    
    int n = Convert.ToInt32(ns["key2"]);
                    Console.WriteLine(s 
    + "" + n.ToString());
                }

                
    finally
                
    {
                    Console.Read();
                }

            }

        }

    }


    结果执行老是出现异常,在vs2k3里这样的代码运行都很正常的!
    请问:在2005中该怎么样读取配置文件中的信息?

  • 相关阅读:
    CodeForces 1025G Company Acquisitions
    Luogu P4271 [USACO18FEB]New Barns P
    Luogu P1625 求和
    SP1772 Find The Determinant II
    CodeForces 1408G Clusterization Counting
    CodeForces 1420E Battle Lemmings
    设计模式——工厂模式
    设计模式——适配器模式
    rabbitMQ centos7 的安装
    dubbo spring 的使用
  • 原文地址:https://www.cnblogs.com/JLL/p/204730.html
Copyright © 2011-2022 走看看