Winterdom

If you want to declare a method that has a ref argument, you'll want to do it with a tracking reference. If the argument type is a ref class, you'll do it like this:


void ReplaceString(String^% s)
{
   Console::WriteLine(s);
   s = "New string";
}

int main()
{
   String^ s = "This is a string";
   ReplaceString(s);
   Console::WriteLine(s);
}

If the type was a value type, then this would work:


void ReplaceInt(int% i)
{
   Console::WriteLine(i);
   i = 8;
}

int main()
{
   int i = 1;
   ReplaceInt(i);
   Console::WriteLine(i);
}

As you can see here, these are just ref-parameters, meaning they are both In/Out. If you wanted to make sure they are marked in metadata as out only (such as you can with C#'s out modifier), you'd need to do use the [Out] attribute, like this:


using namespace System::Runtime::InteropServices;

void GetString([Out] String^% s)
{
   s = "Super String";
}

int main()
{
   String^ s = nullptr;
   GetString(s);
   Console::WriteLine(s);
}
.: tomasr | 2004-10-10 18:55:45 :.