Configuration.AppSettings Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the AppSettingsSection object configuration section that applies to this Configuration object.
public:
property System::Configuration::AppSettingsSection ^ AppSettings { System::Configuration::AppSettingsSection ^ get(); };
public System.Configuration.AppSettingsSection AppSettings { get; }
member this.AppSettings : System.Configuration.AppSettingsSection
Public ReadOnly Property AppSettings As AppSettingsSection
An AppSettingsSection object representing the appSettings
configuration section that applies to this Configuration object.
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());
}
Try
Dim appSettings As AppSettingsSection = TryCast(config.AppSettings, 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.
Dim settings As KeyValueConfigurationCollection = config.AppSettings.Settings
' Display each KeyValueConfigurationElement.
For Each keyValueElement As KeyValueConfigurationElement In settings
Console.WriteLine("Key: {0}", keyValueElement.Key)
Console.WriteLine("Value: {0}", keyValueElement.Value)
Console.WriteLine()
Next keyValueElement
Catch e As ConfigurationErrorsException
Console.WriteLine("Using AppSettings property: {0}", e.ToString())
End Try
Use the AppSettings property to access and change the appSettings
configuration section defined by default in the open configuration file.
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: