The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
CounterCreationDataCollection::IndexOf Method (CounterCreationData^)
.NET Framework (current version)
Returns the index of a CounterCreationData object in the collection.
Assembly: System (in System.dll)
Parameters
- value
-
Type:
System.Diagnostics::CounterCreationData^
The CounterCreationData object to locate in the collection.
Return Value
Type: System::Int32The zero-based index of the specified CounterCreationData, if it is found, in the collection; otherwise, -1.
The following example retrieves CounterCreationData entries from a CounterCreationDataCollection and uses the IndexOf method to display their names and indexes.
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() ); array<CounterCreationData^>^ myCounterCreationData = gcnew array<CounterCreationData^>(numberOfCounters); for ( int i = 0; i < numberOfCounters; i++ ) { Console::Write( "Enter the counter name for {0} counter ", i ); myCounterCreationData[ i ] = gcnew CounterCreationData; myCounterCreationData[ i ]->CounterName = Console::ReadLine(); } CounterCreationDataCollection^ myCounterCollection = gcnew CounterCreationDataCollection( myCounterCreationData ); CounterCreationData^ myInsertCounterCreationData = gcnew 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 = gcnew 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" ); }
.NET Framework
Available since 1.1
Available since 1.1
Show: