Configuration.AppSettings Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan bagian AppSettingsSection konfigurasi objek yang berlaku untuk objek ini Configuration .
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
Nilai Properti
Objek AppSettingsSection yang mewakili bagian appSettings
konfigurasi yang berlaku untuk objek ini Configuration .
Contoh
Contoh kode berikut menunjukkan cara menggunakan AppSettings properti .
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
Keterangan
AppSettings Gunakan properti untuk mengakses dan mengubah bagian konfigurasi yang appSettings
ditentukan secara default dalam file konfigurasi terbuka.