用IronPython 调用C# 封装的接口,其中接口中含有List<string> 参数,报错:expected List[str], got list

用IronPython 调用C# 封装的接口,C# 接口中含有List<string> 参数,直接使用Python 的数组报错:expected List[str], got list

解决办法:

转化python 的数组为C# 的List<string>,步骤如下:

1.添加c#的引用

  import clr
  clr.AddReference('System.Collections')
  from System.Collections.Generic import List

2.定义python 的数组

   pyList=["aa","bb"]

3.转化python 的数组到C#的List<string>

   csList=List[str](pyList)

 

posted @ 2025-03-18 20:55  cdxy2005  阅读(21)  评论(0)    收藏  举报