Export (0) Print
Expand All

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 _
)
[C#]
public void CopyTo(
 EventLogEntry[] entries,
 int index
);
[C++]
public: void CopyTo(
 EventLogEntry* entries[],
 int index
);
[JScript]
public function CopyTo(
   entries : EventLogEntry[],
 index : int
);

Parameters

entries
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.
index
The zero-based index in the array at which copying begins.

Remarks

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.

Example

[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 " + _
                        myEventLogEntry.TimeGenerated)
End While

[C#] 

         // 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);
         }

[C++] 

        // 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 =
                __try_cast<EventLogEntry*>(myEnumerator->Current);
            Console::WriteLine(S"The LocalTime the Event is generated is {0}", 
                __box(myEventLogEntry->TimeGenerated));
        }

[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.

Requirements

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

Show:
© 2014 Microsoft