Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For modification of elements, one option is to manually iterate the dictionary using a for loop, e.g.:</p> <pre><code>Dictionary&lt;string, string&gt; test = new Dictionary&lt;string, string&gt;(); int dictionaryLength = test.Count(); for (int i = 0; i &lt; dictionaryLength; i++) { test[test.ElementAt(i).Key] = "Some new content"; } </code></pre> <p>Be weary though, that if you're also adding to the Dictionary, you must increment dictionaryLength (or decrement it if you move elements) appropriately.</p> <p>Depending on what exactly you're doing, and if order matters, you may wish to use a SortedDictionary instead.</p> <p>You could extend this by updating dictionaryLength explicitly by recalling test.Count() at each iteration, and also use an additional list containing a list of keys you've already modified and so on and so forth if there's a danger of missing any, it really depends what you're doing as much as anything and what your needs are.</p> <p>You can further get a list of keys using test.Keys.ToList(), that option would work as follows:</p> <pre><code>Dictionary&lt;string, string&gt; test = new Dictionary&lt;string, string&gt;(); List&lt;string&gt; keys = test.Keys.ToList(); foreach (string key in keys) { test[key] = "Some new content"; } IEnumerable&lt;string&gt; newKeys = test.Keys.ToList().Except(keys); if(newKeys.Count() &gt; 0) // Do it again or whatever. </code></pre> <p>Note that I've also shown an example of how to find out whether any new keys were added between you getting the initial list of keys, and completing iteration such that you could then loop round and handle the new keys.</p> <p>Hopefully one of these options will suit (or you may even want to mix and match- for loop on the keys for example updating that as you go instead of the length) - as I say, it's as much about what precisely you're trying to do as much as anything.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. 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