CounterCreationDataCollection Constructor (CounterCreationData[])


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the CounterCreationDataCollection class by using the specified array of CounterCreationData instances.

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

public CounterCreationDataCollection(
	CounterCreationData[] value


Type: System.Diagnostics.CounterCreationData[]

An array of CounterCreationData instances with which to initialize this CounterCreationDataCollection.

Exception Condition

value is null.

The following example demonstrates how to create a CounterCreationDataCollection object by using a CounterCreationData array.

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);
    // Create the category.
       "Sample Category",
    PerformanceCounterCategoryType.SingleInstance, myCounterCollection);

    Console.WriteLine("The list of counters in 'CounterCollection' are :");
    for (int i = 0; i < myCounterCollection.Count; i++)
        Console.WriteLine("Counter {0} is '{1}'", i, myCounterCollection[i].CounterName);
    Console.WriteLine("The category already exists");

.NET Framework
Available since 1.1
Return to top