Esta documentación está archivada y no tiene mantenimiento.

CounterCreationDataCollection.IndexOf (Método)

Actualización: noviembre 2007

Devuelve el índice de un objeto CounterCreationData de la colección.

Espacio de nombres:  System.Diagnostics
Ensamblado:  System (en System.dll)

public int IndexOf(
	CounterCreationData value
)
public int IndexOf(
	CounterCreationData value
)
public function IndexOf(
	value : CounterCreationData
) : int

Parámetros

value
Tipo: System.Diagnostics.CounterCreationData
Objeto CounterCreationData que se va a buscar en la colección.

Valor devuelto

Tipo: System.Int32
Índice de base cero del objeto CounterCreationData especificado si se encuentra en la colección; en caso contrario, -1.

El ejemplo siguiente recupera las entradas CounterCreationData de CounterCreationDataCollection y utiliza el método IndexOf para mostrar sus nombres e índices.

string myCategoryName;
int numberOfCounters;
Console.Write("Enter the category Name : ");
myCategoryName = Console.ReadLine();
// Check if the category already exists or not.
if (!PerformanceCounterCategory.Exists(myCategoryName))
{
    Console.Write("Enter the number of counters : ");
    numberOfCounters = int.Parse(Console.ReadLine());
    CounterCreationData[] myCounterCreationData =
       new CounterCreationData[numberOfCounters];

    for (int i = 0; i < numberOfCounters; i++)
    {
        Console.Write("Enter the counter name for {0} counter ", i);
        myCounterCreationData[i] = new CounterCreationData();
        myCounterCreationData[i].CounterName = Console.ReadLine();
    }
    CounterCreationDataCollection myCounterCollection =
       new CounterCreationDataCollection(myCounterCreationData);
    CounterCreationData myInsertCounterCreationData = new CounterCreationData(
       "CounterInsert", "", PerformanceCounterType.NumberOfItems32);
    // Insert an instance of 'CounterCreationData' in the 'CounterCreationDataCollection'.
    myCounterCollection.Insert(myCounterCollection.Count - 1,
       myInsertCounterCreationData);
    Console.WriteLine("'{0}' counter is inserted into 'CounterCreationDataCollection'",
       myInsertCounterCreationData.CounterName);
    // Create the category.
    PerformanceCounterCategory.Create(myCategoryName, "Sample Category",
    PerformanceCounterCategoryType.SingleInstance, myCounterCollection);

    for (int i = 0; i < numberOfCounters; i++)
    {
        myCounter = new PerformanceCounter(myCategoryName,
           myCounterCreationData[i].CounterName, "", false);
    }
    Console.WriteLine("The index of '{0}' counter is {1}",
       myInsertCounterCreationData.CounterName, myCounterCollection.IndexOf(myInsertCounterCreationData));
}
else
{
    Console.WriteLine("The category already exists");
}


String myCategoryName;
int numberOfCounters;
Console.Write("Enter the category Name : ");
myCategoryName = Console.ReadLine();
// Check if the category already exists or not.
if (!(PerformanceCounterCategory.Exists(myCategoryName))) {
    Console.Write("Enter the number of counters : ");
    numberOfCounters = Int32.Parse(Console.ReadLine());
    CounterCreationData myCounterCreationData[] = new 
        CounterCreationData[numberOfCounters];

    for (int i = 0; i < numberOfCounters; i++) {
        Console.Write("Enter the counter name for {0} counter ",
            System.Convert.ToString(i));
        myCounterCreationData.set_Item(i, new CounterCreationData());
        myCounterCreationData[i].set_CounterName(Console.ReadLine());
    }
    CounterCreationDataCollection myCounterCollection = new 
        CounterCreationDataCollection(myCounterCreationData);
    CounterCreationData myInsertCounterCreationData = new 
        CounterCreationData("CounterInsert", "", 
        PerformanceCounterType.NumberOfItems32);
    // Insert an instance of 'CounterCreationData' in the 
    // 'CounterCreationDataCollection'.
    myCounterCollection.Insert(myCounterCollection.get_Count() - 1,
        myInsertCounterCreationData);
    Console.WriteLine("'{0}' counter is inserted into "
        + "'CounterCreationDataCollection'", 
        myInsertCounterCreationData.get_CounterName());
    // Create the category.
    PerformanceCounterCategory.Create(myCategoryName, 
        "Sample Category", myCounterCollection);

    for (int i = 0; i < numberOfCounters; i++) {
        myCounter = new PerformanceCounter(myCategoryName,
            myCounterCreationData[i].get_CounterName(), "", false);
    }
    Console.WriteLine("The index of '{0}' counter is {1}", 
        myInsertCounterCreationData.get_CounterName(), 
        System.Convert.ToString(myCounterCollection.IndexOf(
        myInsertCounterCreationData)));
}
else {
    Console.WriteLine("The category already exists");
}


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

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0
Mostrar: