gpt4 book ai didi

c# - 如何使用 PythonNET 和 C#.NET 将枚举放入列表中?

转载 作者:行者123 更新时间:2023-11-30 21:40:53 28 4
gpt4 key购买 nike

我有一个 NET 库,我正在使用 Python 和 PythonNET,但不知道如何将枚举放入列表中。 Python 似乎将枚举转换为不适合 List 数据类型的整数。这是一个例子:

import clr
from System.Collections.Generic import List
from System import Array, Enum
import MyLibrary

enum = List[MyLibrary.ResultType] #no errors here
enum.Add(MyLibrary.ResultType.PV)
#TypeError: No method matches given arguments

#and just typing MyLibrary.ResultType.PV I get this result
Out[7]: 0

所以我也尝试创建一个数组——它还会创建一个具有枚举数据类型的空数组,但不允许我为其赋值:

Array[MyLibrary.ResultType](MyLibrary.ResultType.PV) 
#TypeError: Cannot convert 0 to MyLibrary.ResultType[]

谁有办法解决这个问题?欣赏它。

最佳答案

天哪,我简直不敢相信我犯的错误,但事实就是如此。我没有通过初始化创建列表

enum = List[MyLibrary.ResultType]() #the missing () was the reason this didn't work!
enum.Add(MyLibrary.ResultType.PV)

现在它工作得很好。

关于c# - 如何使用 PythonNET 和 C#.NET 将枚举放入列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44078042/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com