2010-06-07 58 views
0

時,我有一些代碼:錯誤使用SharpDevelop的

Outlook.Application outLookApp = new Outlook.Application(); 
Outlook.Inspector inspector = outLookApp.ActiveInspector(); 
Outlook.NameSpace nameSpace = outLookApp.GetNamespace("MAPI"); 
Outlook.MAPIFolder inbox = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); 
String sCriteria = "[SenderEmailAddress] = '[email protected]'"; 
Outlook.Items filteredItems = inbox.Items.Restrict(sCriteria); 
// totaly sure that count > 0; 
Outlook.MailItem item = filteredItems[1]; 

在最後一行我有錯誤:「不能型‘對象’隱式轉換爲‘Microsoft.Office.Interop.Outlook.MailItem’的明確。轉換存在(你是否缺少演員?)「。我不知道爲什麼。之前我使用過VisualStudio 2010,但我的試用版已過期。有沒有希望在SharpDevelop上運行這個?

回答

0

這看起來不像SharpDevelop錯誤,看起來你只需要一個演員。試試這個:

Outlook.MailItem item = (Outlook.MailItem)filteredItems[1]; 

(這是假設在filteredItems的對象都屬於這種類型實際上你可能想測試,如果這是這個任務之前的情況。)

此外,您可以使用Visual Studio 2010 Express - http://www.microsoft.com/express/

+0

感謝這有助於我。但我非常肯定,這段代碼在沒有強制轉換的情況下可以在VS中工作。這些工具有什麼區別嗎? – Sebastian 2010-06-08 06:36:37

+0

您顯示的錯誤來自編譯器,而不是SharpDevelop或Visual Studio。難道你正在用SharpDevelop使用Mono框架嗎?這將使用可能給出不同消息的不同編譯器。或者,也許你在兩個開發環境中對同一個編譯器只有不同的設置。 – 2010-06-08 08:29:48