From iLab Cookbook

Toolkits: HowToIterateThroughTheDictionary

<< 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
    removalKeys.Add(i.Path);

}


foreach(string path in removalKeys)
{
    this.SD.Remove(path);
}
 
Retrieved from http://grouplab.cpsc.ucalgary.ca/cookbook/index.php/Toolkits/HowToIterateThroughTheDictionary
Page last modified on December 31, 2005, at 12:10 AM