This documentation is archived and is not being maintained.

EventLogEntryCollection.CopyTo Method

Copies the elements of the EventLogEntryCollection to an array of EventLogEntry instances, starting at a particular array index.

[Visual Basic]
Public Sub CopyTo( _
   ByVal entries() As EventLogEntry, _
   ByVal index As Integer _
public void CopyTo(
 EventLogEntry[] entries,
 int index
public: void CopyTo(
 EventLogEntry* entries[],
 int index
public function CopyTo(
   entries : EventLogEntry[],
 index : int


The one-dimensional array of EventLogEntry instances that is the destination of the elements copied from the collection. The array must have zero-based indexing.
The zero-based index in the array at which copying begins.


Because new entries are appended to the end of the existing list, stepping through the collection enables you access to entries created after you originally created the EventLogEntryCollection. An array of EventLogEntry instances is fixed at the time it is instantiated, so you cannot read new entries using the array returned by the CopyTo method.


[Visual Basic] 
' 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 " + _
End While


         // Copy the EventLog entries to Array of type EventLogEntry.
         EventLogEntry[] myEventLogEntryArray= 
            new EventLogEntry[myEventLogEntryCollection.Count];
         IEnumerator myEnumerator=myEventLogEntryArray.GetEnumerator();
            EventLogEntry myEventLogEntry =(EventLogEntry)myEnumerator.Current;
            Console.WriteLine("The LocalTime the Event is generated is "


        // 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 =
            Console::WriteLine(S"The LocalTime the Event is generated is {0}", 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

EventLogEntryCollection Class | EventLogEntryCollection Members | System.Diagnostics Namespace | Entries