[英]Calling C# object from IronPython
我有以下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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.