共用方式為


InstanceDataCollectionCollection.CopyTo 方法

定義

從指定索引處開始,將 InstanceDataCollection 執行個體的陣列複製到集合。

public:
 void CopyTo(cli::array <System::Diagnostics::InstanceDataCollection ^> ^ counters, int index);
public void CopyTo (System.Diagnostics.InstanceDataCollection[] counters, int index);
override this.CopyTo : System.Diagnostics.InstanceDataCollection[] * int -> unit
Public Sub CopyTo (counters As InstanceDataCollection(), index As Integer)

參數

counters
InstanceDataCollection[]

要加入至集合之 InstanceDataCollection 執行個體 (由其所包含的計數器識別) 的陣列。

index
Int32

要加入新執行個體的所在位置。

範例

下列程式代碼範例會 CopyTo 使用 方法,將轉換成 InstanceDataCollectionCollection 對象的陣列 InstanceDataCollection 。 數位的每個元素 InstanceDataCollection 都會傳遞至函式以進一步處理。


// Process the InstanceDataCollectionCollection for this category.
PerformanceCounterCategory pcc = new PerformanceCounterCategory(categoryName);
InstanceDataCollectionCollection idColCol = pcc.ReadCategory();
InstanceDataCollection[] idColArray = new InstanceDataCollection[idColCol.Count];

Console.WriteLine("InstanceDataCollectionCollection for \"{0}\" " +
    "has {1} elements.", categoryName, idColCol.Count);

// Copy and process the InstanceDataCollection array.
idColCol.CopyTo(idColArray, 0);

foreach ( InstanceDataCollection idCol in idColArray )
{
    ProcessInstanceDataCollection(idCol);
}

' Process the InstanceDataCollectionCollection for this category.
Dim pcc As New PerformanceCounterCategory(categoryName)
Dim idColCol As InstanceDataCollectionCollection = pcc.ReadCategory()
Dim idColArray(idColCol.Count - 1) As InstanceDataCollection

Console.WriteLine("InstanceDataCollectionCollection for ""{0}"" " & _
    "has {1} elements.", categoryName, idColCol.Count)

' Copy and process the InstanceDataCollection array.
idColCol.CopyTo(idColArray, 0)

Dim idCol As InstanceDataCollection
For Each idCol In idColArray
    ProcessInstanceDataCollection(idCol)
Next idCol

適用於