I've researched about IEnumerable and IEnumerator there's a lot of way on how to make a class useable for foreach statement. But that doesn't answer my question. Why is the EventLogEntryCollection used in foreach loop does not return EventLogEntry? But if I changed var to EventLogEntry it works the way I expected using for loop.
EventLog eventLog1 = new EventLog
{
Log = myLogName,
Source = "sourcy"
};
EventLogEntryCollection collection = eventLog1.Entries;
eventLog1.Close();
foreach (var v in collection)
{
Console.WriteLine(v.Message); //object does not contain definition for Message
}
for (int i = 0; i < collection.Count; i++)
{
Console.WriteLine("The Message of the EventLog is :"
+ collection[i].Message);
}