在Python中调用具有引用参数的.Net函数

San*_*VEE 5 .net ironpython

我在VS2012中使用IronPython并尝试调用.Net函数,该函数接受Ref参数,

Lib.dll

public int GetValue(ref double value)
{
  ...
}
Run Code Online (Sandbox Code Playgroud)

蟒蛇:

import clr
clr.AddReference('Lib.dll')
from LibDll import *

value =0.0
x = GetValue(value)
Run Code Online (Sandbox Code Playgroud)

我错过了什么,在C#中我们ref一起使用变量名,在Python中这是什么?

Sim*_*elt 5

有两种方法可以使用IronPython中的out或ref参数调用方法.

在第一种情况下,呼叫由自动编组处理.返回值和更改的refs包含在一个元组中,并且(可以使用15.1作为示例double传递),如:

(returned, referenced) = GetValue(15.1)
Run Code Online (Sandbox Code Playgroud)

更明确的方法是提供准备好的clr-reference:

refParam = clr.Reference[System.Double](15.1)
result = GetValue(refParam)
Run Code Online (Sandbox Code Playgroud)