我对 C# 和 Office 自动化比较陌生,最近我发现自己试图获取对某人 Outlook 收件箱的引用并按接收时间对电子邮件进行排序。直到我在网络上的其他地方找到了一个解决方案,将收件箱分配给 Microsoft.Office.Interop.Outlook.Items 类型的局部变量,然后对局部变量执行排序并且它可以工作,它才起作用。然而,问题是为什么?我认为在 C# 中的对象是引用,当您声明一个新的 Outlook.Inbox 引用,然后将其分配给用户收件箱中的项目时,它只是作为指向实际电子邮件的附加指针,并不会实际复制每封电子邮件到一个新的集合。所以它应该与在原始引用上调用 Sort 没有什么不同,对吧?显然我错了,所以我 d感谢解释。谢谢!!
using Outlook = Microsoft.Office.Interop.Outlook;
...
Outlook.Folder oInbox = (Outlook.Folder)oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
oInbox.Items.Sort("[Received]", true); //this doesn't produce expected results
Outlook.Items inboxFolder = (Outlook.Items)oInbox.Items;
inboxFolder.Sort("[Received]", true); //this DOES sort the items!