I have a C# .Net console application which calls a C++ .Net class library. However, when the following application is executed, the list becomes empty!!!
If I remove the line as indicated in the comment next to it, the code works. I don't understand the reason for this.
If I want to reallocate the memory for list in the C++ class library as what I am trying to do below, what is the correct way to go about doing it?
C#2005 Console Application
class Caller
{
static void Main(string[] args)
{
Callee callee = new Callee();
List<String> s = new List<String>();
callee.DoSomething(s);
Console.WriteLine(s.Count); // Prints out 0
}
}
C++2005 Class Library
public ref class Callee
{
public:
void DoSomething(List<String^>^ list);
};
void Callee::DoSomething(List<String^>^ list)
{
list = gcnew List<String^>(); // Remove this line and it works
list->Add(gcnew String("Test String 1"));
list->Add(gcnew String("Test String 2"));
}