EventLogEntryCollection.CopyTo(EventLogEntry[], Int32) 方法

定义

从特定数组索引开始,将元素 EventLogEntryCollection 复制到实例数组 EventLogEntry

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

参数

entries
EventLogEntry[]

实例的 EventLogEntry 一维数组,该数组是从集合中复制的元素的目标。 数组必须具有从零开始的索引。

index
Int32

数组中开始复制的从零开始的索引。

示例

以下示例创建一个 EventLogEntry 数组,并使用 CopyTo 该方法将其中 EventLogEntryCollection 的内容复制到其中。


// Copy the EventLog entries to Array of type EventLogEntry.
EventLogEntry[] myEventLogEntryArray =
   new EventLogEntry[myEventLogEntryCollection.Count];
myEventLogEntryCollection.CopyTo(myEventLogEntryArray, 0);
IEnumerator myEnumerator = myEventLogEntryArray.GetEnumerator();
while (myEnumerator.MoveNext())
{
    EventLogEntry myEventLogEntry = (EventLogEntry)myEnumerator.Current;
    Console.WriteLine("The LocalTime the Event is generated is "
       + myEventLogEntry.TimeGenerated);
}
' Copy the EventLog entries to Array of type EventLogEntry.
Dim myEventLogEntryArray(myEventLogEntryCollection.Count-1) As EventLogEntry
myEventLogEntryCollection.CopyTo(myEventLogEntryArray, 0)
Dim myEnumerator As IEnumerator = myEventLogEntryArray.GetEnumerator()
While myEnumerator.MoveNext()
   Dim myEventLogEntry As EventLogEntry = CType(myEnumerator.Current, EventLogEntry)
   Console.WriteLine("The LocalTime the Event is generated is " + _
                        myEventLogEntry.TimeGenerated)
End While

注解

由于新条目追加到现有列表中,因此单步执行集合使你能够访问最初创建 EventLogEntryCollection后创建的条目。 实例化时固定实例 EventLogEntry 数组。 因此,不能通过使用方法返回的 CopyTo 数组来读取新条目。

适用于

另请参阅