Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
AppSettings Property
Collapse the table of content
Expand the table of content

ConfigurationManager.AppSettings Property

Gets the AppSettingsSection data for the current application's default configuration.

Namespace: System.Configuration
Assembly: System.Configuration (in system.configuration.dll)

public static NameValueCollection AppSettings { get; }
/** @property */
public static NameValueCollection get_AppSettings ()

public static function get AppSettings () : NameValueCollection

Not applicable.

Property Value

Returns a NameValueCollection object that contains the contents of the AppSettingsSection object for the current application's default configuration.

Exception typeCondition

ConfigurationErrorsException

Could not retrieve a NameValueCollection object with the application settings data.

A AppSettingsSection object contains the contents of the configuration file's appSettings section.

The following code example shows how to use the AppSettings property.

// Show how to use AppSettings.
static void DisplayAppSettings()
{

    // Get the AppSettings collection.
    NameValueCollection appSettings =
       ConfigurationManager.AppSettings;

    string[] keys = appSettings.AllKeys;

    Console.WriteLine();
    Console.WriteLine("Application appSettings:");

    // Loop to get key/value pairs.
    for (int i = 0; i < appSettings.Count; i++)

        Console.WriteLine("#{0} Name: {1} Value: {2}",
          i, keys[i], appSettings[i]);

}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft