用ref或out参数编写铁python方法

我需要将以下C#方法转换为相同的IronPhyton方法

private void GetTP(string name, out string ter, out int prov) { ter = 2; prov = 1; } 

在python中(因此在IronPython中)你不能改变一个不可变的参数(比如字符串)

因此,您无法直接将给定代码转换为python,但您必须执行以下操作:

 def GetTP(name): return tuple([2, 1]) 

当你打电话时,你必须做:

 retTuple = GetTP(name) ter = retTuple[0] prov = retTuple[1] 

当你在IronPython中调用包含out / ref参数的C#方法时,这是相同的行为。

事实上,在这种情况下,IronPython返回out / ref参数的元组,如果返回值是元组中的第一个。

编辑:实际上可以用out / ref参数覆盖一个方法,看看这里:

http://ironpython.net/documentation/dotnet/dotnet.html#methods-with-ref-or-out-parameters

像这样的Python脚本应该工作:

 ter = clr.Reference[System.String]() prov = clr.Reference[System.Int32]() GetTP('theName', ter, prov) print(ter.Value) print(prov.Value)