英語で読む

次の方法で共有


ConfigurationSection コンストラクター

定義

ConfigurationSection クラスの新しいインスタンスを初期化します。

C#
protected ConfigurationSection ();

次の例は、ConfigurationSection コンストラクターを使用する方法を示しています。 この例では、 という名前 CustomSectionのカスタム セクション クラスが作成されていることを前提としています。 このようなクラスの例については、クラスの概要に関するページを ConfigurationSection 参照してください。

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());
    }
}

注釈

コンストラクターを ConfigurationSection 使用するには、最初にカスタム セクション型を定義する必要があります。 例については、クラスの概要を ConfigurationSection 参照してください。

適用対象

製品 バージョン
.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