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

适用于