title: How to iterate through Dictionary without using foreach
body: <p>I am not sure if the title formulates it well so sorry.</p>
  
  <p>I basically have a bunch of elements listing targets for a communication. I placed them in a dictionary though i am open to moving them to a different data structure.  My problem is that i have a tree-like structure where a key is a branch and each branch has many leaves.  Both the branch and the leaves have names stored in strings (cannot be numeral).</p>
  
  <pre><code>private Dictionary &lt; string, string[]&gt; targets;
  </code></pre>
  
  <p>For each element in the dictionary i must send a communication, and when the target answers i go to the next target and start over.  So after searching i am faced with these dilemmas:</p>
  
  <ul>
  <li>I cannot use the usual foreach because i need to keep the pointer in memory to pass it in between threads.</li>
  <li>Since dictionaries are random access it is difficult to keep a pointer </li>
  <li>When i receive a communication i must verify if the origins are from a target, so i like the dictionary.contains method for that.</li>
  </ul>
  
  <p>I am fairly new at C#, so the answer is probably obvious but i am finding a hard time finding a data structure that fits my needs.  What would be the simplest solution?  Can somebody suggest anything?</p>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>I think my post has confused many, and they are sort of stuck on the terms pointers and threads.  By threads i don`t mean that they are parallel, simply that i cannot use a <em>foreach</em> or a loop as the next thread that does the next iteration is triggered by incoming communication.  This mechanism cannot be changed at the moment, just the iteration must be.  By pointer i wasn't referring to the memory pointers often used in C, i just meant something that points to where you are in a list.  Sorry i am a Java programmer so i might be using confusing terms.</p>
  
  <p>I noticed the <em>Enumerator</em> is often inherited and that it can be used with structures such as Dictionary and Linked List.  Examples i find talk about this sub structure being encapsulated, and shows <em>foreach</em> loops as examples.</p>
  
  <p>Would it be possible to use <em>GetEnumerator</em>() in some way that the enumerator would remember the current position even when accessed through a different thread?</p>
  
  <p>I am off to test these on my own, but if any input from more experienced people is always appreciated!</p>