簡體   English   中英

使用 clr pytho.net 將參數(帶 ref)和字符串數組傳遞到 .net function

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

我在 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)


不幸的是我有這個錯誤。

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)

我不明白為什么,而且在 pytho.net 上搜索東西有點復雜,因為沒有太多適合初學者的文檔。 我試圖用Array[str]([])定義我的 ref 參數,但沒有成功。

您看到的錯誤發生在您的DrawdownTable中。 它得到了您創建的 arrays,但您試圖訪問一個索引錯誤的元素(可能來自其中一個)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM