【问题标题】:Pass C# Map collection to Axapta code将 C# Map 集合传递给 Axapta 代码
【发布时间】:2014-04-01 07:54:56
【问题描述】:

我有返回字典的 C# 类和方法。我可以在 Axapta 中创建此类的实例,调用此方法并将集合返回给 Axapta,但我无法遍历此集合并获取其键和值。

这是我的 Axapta 代码:

ClrObject  obj;
;
obj = document.findText("some"); // returns Dictionary<string, string>
length = obj.get_Count(); // returns 5 (fine!)
obj.MoveNext(); // doesn't works 

for (i = 0; i < length; i++ )
{
   obj.get_Key(i);  // doesn't work
}

是一种在 Axapta 中迭代字典的方法吗?

【问题讨论】:

    标签: c# .net axapta x++ dynamics-ax-2009


    【解决方案1】:

    字典上既没有get_Key 也没有MoveNext 方法。

    MoveNext 必须在枚举器上调用。也就是说,您可以通过在字典上调用 GetEnumerator 来检索一个,然后使用它:

    System.Collections.Specialized.StringDictionary dotNetStringDict;
    System.Collections.IEnumerator dotNetEnumerator;
    System.Collections.DictionaryEntry dotNetDictEntry;
    str tempValue;
    ;
    
    dotNetStringDict = new System.Collections.Specialized.StringDictionary();
    dotNetStringDict.Add("Key_1", "Value_1");
    dotNetStringDict.Add("Key_2", "Value_2");
    dotNetStringDict.Add("Key_3", "Value_3");
    
    dotNetEnumerator = dotNetStringDict.GetEnumerator();
    while (dotNetEnumerator.MoveNext())
    {
        dotNetDictEntry = dotNetEnumerator.get_Current();
        tempValue = dotNetDictEntry.get_Value();
        info(tempValue);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 2018-01-09
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多