ConnectionStringSettingsCollection.RemoveAt(Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從集合中的指定之索引處移除 ConnectionStringSettings 物件。
public:
void RemoveAt(int index);
public void RemoveAt (int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)
參數
- index
- Int32
集合中 ConnectionStringSettings 物件的索引。
範例
下列範例示範如何移除 ConnectionStringSettings 集合中指定索引處的物件。
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