我有返回字典的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中迭代字典的一种方式吗?
发布于 2014-04-02 12:38:33
字典上既没有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);
}https://stackoverflow.com/questions/22779862
复制相似问题