vs2005中讀配置文件的方法變了,比如說在winForm下讀app.config文檔吧,明明MSDN上說用:
System.Configuration.ConfigurationManager類,我日根本這個類都沒有。MSDN中還貼出了一些代碼:(C#)
// Create a custom section.
static UsingConfigurationManager()
{
    // Get the application configuration file.
    System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);
 
    // If the section does not exist in the configuration
    // file, create it and save it to the file.
    if (config.Sections[customSectionName] == null)
    {
        custSection = new CustomSection();
        config.Sections.Add(customSectionName, custSection);
        custSection =
            config.GetSection(customSectionName) as CustomSection;
        custSection.SectionInformation.ForceSave = true;
        config.Save(ConfigurationSaveMode.Full);
    }
}你說這是什麼代碼,靜態方法沒有void 也沒有反回類型,不有上面的 as 關健字是什麼意思啊,
唉,真受不了vs2005。

解决方案 »

  1.   

    這個類肯定有,你看一下你有沒有添加system.configuration.dll引用
    MSDN上也說得很清楚啦
    至于as是什麼意思,你還是找本講C#語法的書看看吧
      

  2.   

    呵呵..偶比较喜欢用.net资源文件保存设置.
      

  3.   

    as 是 类型转换不能转返回null
      

  4.   

    1.
    果然是我沒加入參考,但是奇怪是沒加參考 System.Configuration 也會自出在IDE中出來。唉。
    2.
    as 是指類型轉換不丟異常,我剛看了一下MSDN,謝謝。
    相當於下面語句的意思:
    expression is type ? (type)expression : (type)null好,謝謝各位。給分了