CounterCreationDataCollection.AddRange Method

Definition

Adds multiple CounterCreationData instances to the collection.

Overloads

AddRange(CounterCreationData[])

Adds the specified array of CounterCreationData instances to the collection.

AddRange(CounterCreationDataCollection)

Adds the specified collection of CounterCreationData instances to the collection.

AddRange(CounterCreationData[])

Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs

Adds the specified array of CounterCreationData instances to the collection.

C#
public void AddRange(System.Diagnostics.CounterCreationData[] value);

Parameters

value
CounterCreationData[]

An array of CounterCreationData instances to append to the existing collection.

Exceptions

value is null.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

AddRange(CounterCreationDataCollection)

Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs
Source:
CounterCreationDataCollection.cs

Adds the specified collection of CounterCreationData instances to the collection.

C#
public void AddRange(System.Diagnostics.CounterCreationDataCollection value);

Parameters

value
CounterCreationDataCollection

A collection of CounterCreationData instances to append to the existing collection.

Exceptions

value is null.

Examples

The following example demonstrates how to use the AddRange(CounterCreationDataCollection) method overload to add CounterCreationData objects from one CounterCreationDataCollection to another CounterCreationDataCollection.

C#
using System;
using System.Diagnostics;

public class CounterDataCollectionExample
{
    public static void Main()
    {
        try
        {

            string myCategoryName;
            int numberOfCounters;
            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);
            Console.Write("Enter the category Name : ");
            myCategoryName = Console.ReadLine();
            // Check if the category already exists or not.
            if (!PerformanceCounterCategory.Exists(myCategoryName))
            {
                CounterCreationDataCollection myNewCounterCollection =
                   new CounterCreationDataCollection();
                // Add the 'CounterCreationDataCollection' to 'CounterCreationDataCollection' object.
                myNewCounterCollection.AddRange(myCounterCollection);

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

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

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10