title: C# - Removing Items from Dictionary in while loop
body: <p>I have this and all seems to work fine but not sure why and if its valid.</p>
  
  <pre><code>        Dictionary&lt;string, List&lt;string&gt;&gt; test = new Dictionary&lt;string, List&lt;string&gt;&gt;();
  
          while (test.Count &gt; 0)
          {
              var obj = test.Last();
              MyMethod(obj);
              test.Remove(obj.Key);
          }
  </code></pre>
  
  <p><strong>Update: Thanks for the answers, I have updated my code to explain why I don't do Dictionary.Clear();</strong></p>