ConnectionStringSettingsCollection.IndexOf(ConnectionStringSettings) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the collection index of the passed ConnectionStringSettings object.
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
Parameters
- settings
- ConnectionStringSettings
A ConnectionStringSettings object in the collection.
Returns
The collection index of the specified ConnectionStringSettingsCollection object.
Examples
The following example shows how to get the index of the specified ConnectionStringSettings object.
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
Applies to
See also
Spolupracujte s námi na GitHubu
Zdroj tohoto obsahu najdete na GitHubu, kde můžete také vytvářet a kontrolovat problémy a žádosti o přijetí změn. Další informace najdete v našem průvodci pro přispěvatele.
Váš názor
https://aka.ms/ContentUserFeedback.
Připravujeme: V průběhu roku 2024 budeme postupně vyřazovat problémy z GitHub coby mechanismus zpětné vazby pro obsah a nahrazovat ho novým systémem zpětné vazby. Další informace naleznete v tématu:Odeslat a zobrazit názory pro