Loop through dotnet Dictionary

jimmyfjimmyf Member Posts: 104
I would like to use a dotnet Dictionary to hold a key value pair. I can add items to the dictionary however I cannot workout how to loop through the dictionary and extract the Key and the value into separate variables.

I am using the following dotnet datatypes..

Dict System.Collections.Generic.Dictionary`2.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Element System.Object.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

FOREACH Element IN Dict DO
BEGIN
MESSAGE(FORMAT(Element));
END;

The output of the Message is the key and value in square brackets e.g. [key,value]
However I would like to retrieve the key and value separately.

Thank you

Answers

  • KishormKishorm Member Posts: 921
    Try this....
    FOREACH Element IN Dict DO BEGIN
      MESSAGE(FORMAT(Element.key));
      MESSAGE(FORMAT(Element.value));
    END;
    
  • archer89archer89 Member Posts: 337
    Element is of type System.Collections.Generic.KeyValuePair`2.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and has properties Key and Value, which you can write out separately.
    best regards
    Franz Kalchmair, MVP
    Alias: Jonathan Archer

    please like / agree / verify my answer, if it was helpful for you. thx.
    Blog: http://moxie4nav.wordpress.com/
  • jimmyfjimmyf Member Posts: 104
    Great, Thank you both very much for your help. Works perfectly
Sign In or Register to comment.