Export (0) Print
Expand All

CounterCreationDataCollection.Remove Method

Removes a CounterCreationData object from the collection.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

public virtual void Remove(
	CounterCreationData value


Type: System.Diagnostics.CounterCreationData

The CounterCreationData to remove from the collection.


value is null.


value is not a CounterCreationData object.


value does not exist in the collection.

The following example demonstrates how to use the Remove method to delete a CounterCreationData object from the 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'.

       "Sample Category",
    PerformanceCounterCategoryType.SingleInstance, myCounterCollection);

    if (myCounterCreationData.Length > 0)
        if (myCounterCollection.Contains(myCounterCreationData[0]))
            Console.WriteLine("'{0}' counter is removed from the " +
               "CounterCreationDataCollection", myCounterCreationData[0].CounterName);
        Console.WriteLine("The counters does not exist");
    Console.WriteLine("The category already exists");

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft