ConfigurationSection Constructeur

Définition

Initialise une nouvelle instance de la classe ConfigurationSection.

C#
protected ConfigurationSection ();

Exemples

L'exemple suivant illustre comment utiliser le ConfigurationSection. Cet exemple suppose que vous avez créé une classe de section personnalisée nommée CustomSection. Pour obtenir un exemple de cette classe, consultez la vue d’ensemble de la ConfigurationSection classe.

C#

// Create a custom section.
static void CreateSection()
{
    try
    {

        CustomSection customSection;

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

        // Create the section entry  
        // in the <configSections> and the 
        // related target section in <configuration>.
        if (config.Sections["CustomSection"] == null)
        {
            customSection = new CustomSection();
            config.Sections.Add("CustomSection", customSection);
            customSection.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Full);
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}

Remarques

Pour utiliser le ConfigurationSection constructeur, vous devez d’abord définir un type de section personnalisé. Pour obtenir un exemple, consultez la vue d’ensemble de la ConfigurationSection classe.

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