ConnectionStringSettingsCollection.IndexOf Method

Note: This method is new in the .NET Framework version 2.0.

Returns the index in the collection of the passed ConnectionStringSettings object.

Namespace: System.Configuration
Assembly: System.Configuration (in system.configuration.dll)

public int IndexOf (
	ConnectionStringSettings settings
)
public int IndexOf (
	ConnectionStringSettings settings
)
public function IndexOf (
	settings : ConnectionStringSettings
) : int

Parameters

settings

A ConnectionStringSettings object in the collection.

Return Value

The collection index of the specified ConnectionStringSettingsCollection object.

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());
    


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Show: