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 數位來讀取新專案。

適用於

另請參閱