EventLogEntryCollection.Count 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得事件日誌中的條目數量(即集合中的 EventLogEntry 元素數量)。
public:
property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer
屬性值
事件日誌中目前的條目數量。
實作
範例
以下範例示範如何利用該 Count 屬性遍歷 EventLogEntryCollection 物件。
// Create a new EventLog object.
EventLog myEventLog1 = new EventLog();
myEventLog1.Log = myLogName;
// Obtain the Log Entries of the Event Log
EventLogEntryCollection myEventLogEntryCollection = myEventLog1.Entries;
Console.WriteLine("The number of entries in 'MyNewLog' = " +
myEventLogEntryCollection.Count);
// Display the 'Message' property of EventLogEntry.
for (int i = 0; i < myEventLogEntryCollection.Count; i++)
{
Console.WriteLine("The Message of the EventLog is :" +
myEventLogEntryCollection[i].Message);
}
' Create a new EventLog object.
Dim myEventLog1 As New EventLog()
myEventLog1.Log = myLogName
' Obtain the Log Entries of the Event Log
Dim myEventLogEntryCollection As EventLogEntryCollection = myEventLog1.Entries
Console.WriteLine("The number of entries in 'MyNewLog' = " + _
myEventLogEntryCollection.Count.ToString())
' Display the 'Message' property of EventLogEntry.
Dim i As Integer
For i = 0 To myEventLogEntryCollection.Count - 1
Console.WriteLine("The Message of the EventLog is :" + _
myEventLogEntryCollection(i).Message)
Next i
備註
an EventLogEntryCollection 代表日誌中所有條目的動態清單。 因此,在你所建立的實例存EventLogEntryCollection續期間,財產Count可能會改變。 通常最好直接處理屬性, Count 而不是將其值指派給變數。