AppSettingsSection.Settings Propriété

Définition

Obtient une collection de paires clé/valeur qui contient des paramètres d’application.

C#
[System.Configuration.ConfigurationProperty("", IsDefaultCollection=true)]
public System.Configuration.KeyValueConfigurationCollection Settings { get; }
C#
public System.Configuration.KeyValueConfigurationCollection Settings { get; }

Valeur de propriété

Une collection de paires clé/valeur qui contient les paramètres d'application du fichier de configuration.

Attributs

Exemples

L’exemple suivant utilise la Settings propriété pour lire les appSettings valeurs.

C#
// This function shows how to read the key/value
// pairs (settings collection)contained in the 
// appSettings section.
static void ReadAppSettings()
{
    try
    {

        // Get the configuration file.
        System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

        // Get the appSettings section.
        System.Configuration.AppSettingsSection appSettings =
            (System.Configuration.AppSettingsSection)config.GetSection("appSettings");

        // Get the auxiliary file name.
        Console.WriteLine("Auxiliary file: {0}", config.AppSettings.File);

        // Get the settings collection (key/value pairs).
        if (appSettings.Settings.Count != 0)
        {
            foreach (string key in appSettings.Settings.AllKeys)
            {
                string value = appSettings.Settings[key].Value;
                Console.WriteLine("Key: {0} Value: {1}", key, value);
            }
        }
        else
        {
            Console.WriteLine("The appSettings section is empty. Write first.");
        }
    }
    catch (Exception e)
    {
        Console.WriteLine("Exception raised: {0}",
            e.Message);
    }
}

S’applique à

Produit Versions
.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, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9