共用方式為


ConfigurationSectionGroupCollection.Remove(String) 方法

定義

從這個 ConfigurationSectionGroup 物件中移除具有指定之名稱的 ConfigurationSectionGroupCollection 物件。

public:
 void Remove(System::String ^ name);
public void Remove (string name);
member this.Remove : string -> unit
Public Sub Remove (name As String)

參數

name
String

要移除的區段群組名稱。

範例

下列程式碼範例示範如何使用 Remove 方法。

       static void Remove()
       {

           try
           {

               System.Configuration.Configuration config =
                   ConfigurationManager.OpenExeConfiguration(
                  ConfigurationUserLevel.None);

               ConfigurationSectionGroup customGroup =
                   config.SectionGroups.Get("CustomGroup");

               if (customGroup != null)
               {
                   config.SectionGroups.Remove("CustomGroup");
                   config.Save(ConfigurationSaveMode.Full);
               }
               else
                   Console.WriteLine(
                       "CustomGroup does not exists.");
           }
           catch (ConfigurationErrorsException err)
           {
               Console.WriteLine(err.ToString());
           }
       }
Shared Sub Remove()
   
   Try
      
         Dim config _
     As System.Configuration.Configuration = _
     ConfigurationManager.OpenExeConfiguration( _
     ConfigurationUserLevel.None)

         Dim groups _
         As ConfigurationSectionGroupCollection = _
         config.SectionGroups

         Dim customGroup _
         As ConfigurationSectionGroup = groups.Get("CustomGroup")
      
      If Not (customGroup Is Nothing) Then
         config.SectionGroups.Remove("CustomGroup")
         config.Save(ConfigurationSaveMode.Full)
      Else
             Console.WriteLine( _
             "CustomGroup does not exists.")
      End If
   
   Catch err As ConfigurationErrorsException
      Console.WriteLine(err.ToString())
   End Try
End Sub

適用於

另請參閱