I was wondering why this code does not work in C++/CLI but damn easy in C#?
List<Process^>^ processList = gcnew List<Process^>(
Process::GetProcessesByName(this->processName)););
error C2664: ‘System::Collections::Generic::List::List(System::Collections::Generic::IEnumerable ^)’ : cannot convert parameter 1 from ‘cli::array ^’ to ‘System::Collections::Generic::IEnumerable ^’
Here is what I come up with. Did perfectly well. 🙂
List<Process^>^ processList = gcnew List<Process^>(
safe_cast<System::Collections::Generic::IEnumerable<Process^>^>
(Process::GetProcessesByName(this->processName)));
You need to use
safe_cast. According to the MSDN documentation onSystem::Array,As you can see, the cast must be done explicitly in C++ at runtime, e.g.