ConnectionStringSettingsCollection.IndexOf(ConnectionStringSettings) Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Devuelve el índice de la colección del objeto ConnectionStringSettings pasado.
public:
int IndexOf(System::Configuration::ConnectionStringSettings ^ settings);
public int IndexOf (System.Configuration.ConnectionStringSettings settings);
member this.IndexOf : System.Configuration.ConnectionStringSettings -> int
Public Function IndexOf (settings As ConnectionStringSettings) As Integer
Parámetros
- settings
- ConnectionStringSettings
Objeto ConnectionStringSettings de la colección.
Devoluciones
Índice en la colección del objeto ConnectionStringSettingsCollection especificado.
Ejemplos
En el ejemplo siguiente se muestra cómo obtener el índice del objeto especificado ConnectionStringSettings .
static void GetIndex()
{
try
{
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Clear the connection strings collection.
ConnectionStringsSection csSection =
config.ConnectionStrings;
ConnectionStringSettingsCollection csCollection =
csSection.ConnectionStrings;
// Get the connection string setting element
// with the specified name.
ConnectionStringSettings cs =
csCollection["ConnStr0"];
// Get its index;
int index = csCollection.IndexOf(cs);
Console.WriteLine(
"Connection string settings index: {0}",
index.ToString());
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine(err.ToString());
}
}
Shared Sub GetIndex()
Try
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
' Get the connection string setting element
' with the specified name.
Dim cs _
As ConnectionStringSettings = _
csCollection("ConnStr0")
' Get its index;
Dim index As Integer = _
csCollection.IndexOf(cs)
Console.WriteLine( _
"Connection string settings index: {0}", _
index.ToString())
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub