简体   繁体   English

使用 clr pytho.net 将参数(带 ref)和字符串数组传递到 .net function

[英]passing parameter (with ref) and string array into a .net function with clr pythonnet

I have this function in a dll that i imported via clr in python with asNetArray function that i found somewhere in the.net.我在 dll 中有这个 function,我通过 clr 在 python 中导入了 asNetArray function,我在 .net 的某个地方找到了它。

public static double DrawdownTable(ref System.Array resDrawdown, ref System.Array resPeak, ref System.Array resThrough, ref System.Array resRecover, System.Array dateVector, System.Array security)
resDrawdown = asNetArray(np.array([]))
    resPeak = asNetArray(np.array([]))
    resThrough = asNetArray(np.array([]))
    resRecover = asNetArray(np.array([]))

    date=date.strftime('%Y-%m-%d').to_list()
    date = Array[str](date)
    #table =  Engine.DrawdownTable(asNetArray(date),asNetArray(security))
    (result,resDrawdown,resPeak,resThrough,resRecover) = Engine.DrawdownTable(resDrawdown,resPeak,resThrough,resRecover,date,security)


Unfortunately i have this error.不幸的是我有这个错误。

Traceback (most recent call last):
  File "<string>", line 1, in <module>
System.IndexOutOfRangeException: L'index se trouve en dehors des limites du tableau.
   à System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)
   à System.Array.SetValue(Object value, Int32 index)
   à DrawdownTable(Array& resDrawdown, Array& resPeak, Array& resThrough, Array& resRecover, Array dateVector, Array security)

I can't understand why and also it's a bit complicated to search things on pytho.net as there is not much documentation for beginners.我不明白为什么,而且在 pytho.net 上搜索东西有点复杂,因为没有太多适合初学者的文档。 I tried to defined my ref argument with Array[str]([]) but without success.我试图用Array[str]([])定义我的 ref 参数,但没有成功。

The error you see happens in your DrawdownTable .您看到的错误发生在您的DrawdownTable中。 It got the arrays you created, but you tried to access an element (likely from one of them) with bad index.它得到了您创建的 arrays,但您试图访问一个索引错误的元素(可能来自其中一个)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM