我有以下 C# 代码将其编译成 MyMath.dll 程序集。
namespace MyMath {
public class Arith {
public Arith() {}
public int Add(int x, int y) {
return x + y;
}
}
}
我有以下 IronPython 代码来使用这个对象。
import clr
clr.AddReferenceToFile("MyMath.dll")
import MyMath
arith = Arith()
print arith.Add(10,20)
当我使用 IronPython 运行此代码时,出现以下错误。
Traceback (most recent call last): File ipycallcs, line unknown, in Initialize NameError: name 'Arith' is not defined
可能出了什么问题?
已添加
arith = Arith() 应该是 arith = MyMath.Arith()
最佳答案
您应该执行以下操作:
from MyMath import Arith
或者:
from MyMath import *
否则,您必须将 Arith
类称为 MyMath.Arith。
关于c# - 从 IronPython 调用 C# 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3902018/