Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Outlook Add-In Arrays Start at 1?

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?

like image 282
Jake Avatar asked Jul 16 '12 20:07

Jake


1 Answers

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.

like image 172
MvanGeest Avatar answered Sep 27 '22 15:09

MvanGeest