博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ConfigurationManager.AppSettings 属性

Posted on 2010-12-30 10:25  暗夜求真  阅读(3398)  评论(0)    收藏  举报

下面的代码示例演示如何使用 AppSettings 属性获取命名的应用程序设置。

 

例子:

 

// Get appSettings.
static void GetAppSettings()
{
    // Get the appSettings.
    NameValueCollection appSettings =
         ConfigurationManager.AppSettings;
    
    // Get the collection enumerator.
    IEnumerator appSettingsEnum =
        appSettings.Keys.GetEnumerator();

    // Loop through the collection and
    // display the appSettings key, value pairs.
    int i = 0;
    Console.WriteLine("App settings.");
    while (appSettingsEnum.MoveNext())
    {
        string key = appSettings.Keys[i];
        Console.WriteLine("Name: {0} Value: {1}",
        key, appSettings[key]);
        i += 1;
    }

}