【发布时间】:2012-08-28 04:46:23
【问题描述】:
我想知道为什么这段代码在 C++/CLI 中不起作用,但在 C# 中却很简单?
List<Process^>^ processList = gcnew List<Process^>(
Process::GetProcessesByName(this->processName)););
错误 C2664: 'System::Collections::Generic::List::List(System::Collections::Generic::IEnumerable ^)' : 无法将参数 1 从 'cli::array ^' 转换为 'System ::Collections::Generic::IEnumerable ^'
这是我想出的。做得非常好。 :)
List<Process^>^ processList = gcnew List<Process^>(
safe_cast<System::Collections::Generic::IEnumerable<Process^>^>
(Process::GetProcessesByName(this->processName)));
【问题讨论】:
-
sn-p 有点坏了,但这在 VS2008 上运行良好。这是什么版本的编译器? “好的,我知道该怎么做!”这个答案中的短语可能是相关的:stackoverflow.com/a/11164210/17034
标签: c# arrays list c++-cli clr