Configuration.AppSettings Property

 

Gets the AppSettingsSection object configuration section that applies to this Configuration object.

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

public AppSettingsSection AppSettings { get; }

Property Value

Type: System.Configuration.AppSettingsSection

An AppSettingsSection object representing the appSettings configuration section that applies to this Configuration object.

Use the AppSettings property to access and change the appSettings configuration section defined by default in the open configuration file.

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

try
{
    AppSettingsSection appSettings =
        config.AppSettings as AppSettingsSection;
    Console.WriteLine("Section name: {0}",
            appSettings.SectionInformation.SectionName);

    // Get the AppSettings section elements.
    Console.WriteLine();
    Console.WriteLine("Using AppSettings property.");
    Console.WriteLine("Application settings:");
    // Get the KeyValueConfigurationCollection 
    // from the configuration.
    KeyValueConfigurationCollection settings =
      config.AppSettings.Settings;

    // Display each KeyValueConfigurationElement.
    foreach (KeyValueConfigurationElement keyValueElement in settings)
    {
        Console.WriteLine("Key: {0}", keyValueElement.Key);
        Console.WriteLine("Value: {0}", keyValueElement.Value);
        Console.WriteLine();
    }
}
catch (ConfigurationErrorsException e)
{
    Console.WriteLine("Using AppSettings property: {0}",
        e.ToString());
}

.NET Framework
Available since 2.0
Return to top
Show: