Aracılığıyla paylaş


ConnectionStringSettingsCollection.RemoveAt(Int32) Yöntem

Tanım

Koleksiyonda ConnectionStringSettings belirtilen dizindeki nesneyi kaldırır.

public:
 void RemoveAt(int index);
public void RemoveAt (int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)

Parametreler

index
Int32

Koleksiyondaki bir ConnectionStringSettings nesnenin dizini.

Örnekler

Aşağıdaki örnekte, koleksiyonda ConnectionStringSettings belirtilen dizinde nesnesinin nasıl kaldırılacağı gösterilmektedir.

static void RemoveConnectionStrings3()
{

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

        // Clear the connection strings collection.
        ConnectionStringsSection csSection =
            config.ConnectionStrings;
        ConnectionStringSettingsCollection csCollection =
         csSection.ConnectionStrings;

        // Remove the element.
        csCollection.RemoveAt(0);

        // Save the configuration file.
        config.Save(ConfigurationSaveMode.Modified);
        
        Console.WriteLine(
             "Connection string settings removed.");
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub RemoveConnectionStrings3() 
    
    Try
        ' Get the application configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        ' Clear the connection strings collection.
        Dim csSection _
        As ConnectionStringsSection = _
        config.ConnectionStrings
        Dim csCollection _
        As ConnectionStringSettingsCollection = _
        csSection.ConnectionStrings
        
        ' Remove the element.
        csCollection.RemoveAt(0)
        
        ' Save the configuration file.
        config.Save(ConfigurationSaveMode.Modified)
        
        Console.WriteLine( _
        "Connection string settings removed.")

    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try

End Sub

Şunlara uygulanır

Ayrıca bkz.