Exportar (0) Imprimir
Expandir todo

CounterCreationDataCollection.IndexOf (Método)

Devuelve el índice de CounterCreationData en 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

Índice del nuevo objeto de la clase CounterCreationData del que se va a determinar el índice en la colección.

Valor devuelto

Índice de base cero del valor incluido en la colección, si se encuentra; de lo contrario, -1.

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",
      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 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0, 1.1, 1.0

Adiciones de comunidad

AGREGAR
Mostrar:
© 2015 Microsoft