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

CounterCreationDataCollection.Contains (Método)

Actualización: noviembre 2007

Determina si una instancia de CounterCreationData existe en la colección.

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

public bool Contains(
	CounterCreationData value
)
public boolean Contains(
	CounterCreationData value
)
public function Contains(
	value : CounterCreationData
) : boolean

Parámetros

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

Valor devuelto

Tipo: System.Boolean
Es true si el objeto CounterCreationData especificado existe en la colección; en caso contrario, es false.

En el ejemplo siguiente se muestra cómo usar el método Contains para buscar un objeto CounterCreationData en CounterCreationDataCollection.

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();
    // Add the 'CounterCreationData[]' to 'CounterCollection'.
    myCounterCollection.AddRange(myCounterCreationData);

    PerformanceCounterCategory.Create(myCategoryName,
       "Sample Category",
    PerformanceCounterCategoryType.SingleInstance, myCounterCollection);

    if (myCounterCreationData.Length > 0)
    {
        if (myCounterCollection.Contains(myCounterCreationData[0]))
        {
            myCounterCollection.Remove(myCounterCreationData[0]);
            Console.WriteLine("'{0}' counter is removed from the " +
               "CounterCreationDataCollection", myCounterCreationData[0].CounterName);
        }
    }
    else
    {
        Console.WriteLine("The counters does not exist");
    }
}
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[i] = new CounterCreationData();
        myCounterCreationData[i].set_CounterName(Console.ReadLine());
    }
    CounterCreationDataCollection myCounterCollection = new 
        CounterCreationDataCollection();
    // Add the 'CounterCreationData[]' to 'CounterCollection'.
    myCounterCollection.AddRange(myCounterCreationData);

    PerformanceCounterCategory.Create(myCategoryName,
        "Sample Category", myCounterCollection);

    for (int i = 0; i < numberOfCounters; i++) {
        myCounter = new PerformanceCounter(myCategoryName,
            myCounterCreationData[i].get_CounterName(), "", false);
    }
    // Remove an instance of 'CounterCreationData' from
    // 'CounterCollection'.
    if (myCounterCreationData.get_Length() > 0) {
        if (myCounterCollection.Contains(
            myCounterCreationData.get_Item(0))) {
            myCounterCollection.Remove(
                myCounterCreationData.get_Item(0));
            Console.WriteLine("'{0}' counter is removed from the " 
                + "CounterCreationDataCollection",
                myCounterCreationData[0].get_CounterName());
        }
    }
    else {
        Console.WriteLine("The counters does not exist");
    }
}
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: