Q: Using the ref gives me an error...

  • Thread starter Thread starter Visual Systems AB \(Martin Arvidsson\)
  • Start date Start date
V

Visual Systems AB \(Martin Arvidsson\)

Hi!

I'm trying to use the "ref" to return a value, see snippet below.
I execute AddTask first, this executes FindTaskByID.

The compiler gives me this error...
(55): Argument '2': cannot convert from
'Microsoft.Office.Interop.Outlook.TaskItem' to 'ref
Microsoft.Office.Interop.Outlook.TaskItem'

The general idea is to check for a task in outlook, if the task doesn't
exist, create a new task
otherwise update the existing...


public bool FindTaskByID(string taskID, ref Outlook.TaskItem task)
{
task = (Outlook.TaskItem)_mapiFolderTask.Session.GetItemFromID(taskID,
_mapiFolderTask.StoreID);
// True if taskID and the searchedID
return (taskID == task.EntryID.ToString());
}

public string AddTask(string subject,
DateTime intDate, DateTime dueDate,
string status, string priority, string entryID)
{
Outlook.TaskItem Task = (Outlook.TaskItem)
_Outlook.CreateItem(Outlook.OlItemType.olTaskItem);
FindTaskByID(entryID, Task);

**** CODE END *****

Regards
Martin
 
When you call FindTaskByID, you need to specify that you
are passing the value by reference, to do so you would add
the 'ref' keyword to your call making it look something
like:

FindTaskByID(entryID, ref Task);

Just for note, the same thing needs to be done when using
the 'out' keyword, it must be specified on both the
calling side and on the destination side.
 
Back
Top