C # Outlook add-in arrays start at 1?

I hit my head against the wall for 25 minutes, trying to understand why I can’t access the first index of the array, which I tried to make with the array [0]. I continued to get the index of the array from the exception bounds. To see what happens, I tried using the array [1] ... and it worked. In excellence. I have no idea why.

for (int i = 1; i < itemCounter+1; i++) { if (explorer.CurrentFolder.Items[i] is Outlook.MailItem) { //Do something } } 

Everything works perfectly. What's going on here?

+6
source share
2 answers

It looks like the Outlook object model is part of the Office object model, and as indicated by http://msdn.microsoft.com/en-us/library/aa189134%28v=office.10%29.aspx ,

Most collections used in Office applications (except Access) are unidirectional, that is, the index number of the first item in the collection is 1.

In addition, http://msdn.microsoft.com/en-us/library/522xhsa3%28v=vs.90%29.aspx specifically tells us that

To access the first item in the collection in the Microsoft Office application object model, use index 1 instead of 0.

+14
source

Yes, it seems that the elements return a collection object, and, as you know, they are available when using such an array modifier. You should be able to do .ToArray () to get the expected behavior, otherwise you could just use foreach var item in items and get everything in the folder with the construct, which could also end.

+1
source

Source: https://habr.com/ru/post/920628/


All Articles