How To Iterate Through The Dictionary

<< Back to the .Networking page

You can iterate through entries in a shared dictionary. The following code grabs each item in the dictionary and adds it to an array list. Then, it removes each item from the dictionary.

ArrayList removalKeys = new ArrayList();

foreach(GroupLab.Networking.SharedDictionary.Entry i in
    (this.SD["/value/?"] as IEnumerable))

    // note: instead of actually removing each key here
    // we add it to a list of keys to remove after
    // this is necessary because when iterating over an
    // enumeration you cannot modify the shared dictionary


foreach(string path in removalKeys)