我有 python 代码,它保存到 test.py
def Process():
list1 = [1, 2, 3] #list object
return list1
我也有 C# 代码
List<int> list1 = new List<int>(new int[3]);
var runtime = Python.CreateRuntime();
dynamic test = runtime.UseFile(m_sFilename);
var list2 = test.Process();
list1 = (List<int>)list2; << Error
/*
list1[0] = list2[0]; // this code works fine but need how to
list1[1] = list2[1];
list1[2] = list2[2];
*/
当我运行它时,我得到 RuntimeBinderException 未处理
无法将类型“IronPython.Runtime.List”转换为“System.Collections.Generic.List”
如何解决这个问题?
另外如何将列表传递给Python?