共用方式為


使用陣列有效率地列舉資料夾中的專案

此範例示範如何使用 GetArray (Int32 ) 方法,有效率地列舉 Folder 物件中的專案。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

在下列程式代碼範例中,DemoGetArrayForTable 會使用 GetTable (Object, Object) 方法,從 Folder 物件取得 Table 物件。 DemoGetArrayForTable 接著會使用 GetArray 方法傳回 Array 物件, 其中包含數據表中每個數據列的專案。 傳回的 Array 對像是二維數位列,代表 Table 中的一組數據列和數據行值。 陣列是以零為基礎,而不是以一為基底,就像 Outlook 集合的情況一樣。 取得 Array 物件之後,程式代碼會使用 for 循環來列舉數據表。

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void DemoGetArrayForTable()
{
    // Obtain Inbox
    Outlook.Folder folder =
        Application.Session.GetDefaultFolder(
        Outlook.OlDefaultFolders.olFolderInbox)
        as Outlook.Folder;
    Outlook.Table table =
        folder.GetTable("", Outlook.OlTableContents.olUserItems);
    Array tableArray = table.GetArray(table.GetRowCount()) as Array;
    for (int i = 0; i <= tableArray.GetUpperBound(0); i++)
    {
        for (int j = 0; j <= tableArray.GetUpperBound(1); j++)
        {
            Debug.WriteLine(tableArray.GetValue(i, j));
        }
    }
}

另請參閱