I've been banging my head against the wall for 25 minutes trying to figure out why I can't access the 'first' index of an array, which I was trying to do with array[0]. I kept getting an Array Index Out of Bounds Exception. Just to see what would happen, I tried using array[1]...and it worked. Perfectly. I have no idea why.
for (int i = 1; i < itemCounter+1; i++)
{
if (explorer.CurrentFolder.Items[i] is Outlook.MailItem)
{ //Do something }
}
The whole thing works fine. What's going on here?
It appears that the Outlook Object Model is part of the Office Object Model, and as http://msdn.microsoft.com/en-us/library/aa189134%28v=office.10%29.aspx states,
Most collections used in Office applications (except Access) are one-based, that is, the index number of the first item in the collection is 1.
Also, http://msdn.microsoft.com/en-us/library/522xhsa3%28v=vs.90%29.aspx specifically tells us that
To access the first item of a collection in the object model of a Microsoft Office application, use the index 1 instead of 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With