Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>is this the safe way of iterating over a concurrent dictionary? If not, what is the safe way for doing it?</p> </blockquote> <p>Yes, it's safe in that it won't throw an exception. If elements are added or removed after you start iterating, they may or may not be included in the iteration. From the <a href="http://msdn.microsoft.com/en-us/library/dd287131.aspx" rel="nofollow noreferrer"><code>GetEnumerator</code> documentation:</a></p> <blockquote> <p>The enumerator returned from the dictionary is safe to use concurrently with reads and writes to the dictionary, however it does not represent a moment-in-time snapshot of the dictionary. The contents exposed through the enumerator may contain modifications made to the dictionary after GetEnumerator was called.</p> </blockquote> <p>Next:</p> <blockquote> <p>I use the tryRemove method, but what do I do with the outPerson object?</p> </blockquote> <p>Whatever you want with it, including nothing. You could just cast the dictionary to <code>IDictionary&lt;TKey, TValue&gt;</code> and call <code>Remove</code>, or just use <code>TryRemove</code> and ignore the variable afterwards:</p> <pre><code>Person ignored; dictionary.TryRemove(key, out ignored); </code></pre> <p>There's no concept of "clearing [the object] completely" - if you haven't got any references to it, it will be garbage collected. But either way, it's not in the dictionary any more (at least via that key). If you don't use the variable (<code>ignored</code> above) anywhere else in the code, it won't stop the object from being garbage collected.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload