Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li>Yes, you can trust the order of SortedDictionary. It would be pointless otherwise :)</li> <li><p>It would be slightly more efficient without the "let" clause. Just do:</p> <pre><code>var qry = from key in keys from priority in sortedDict where priority.Value.ContainsKey(key) let value = priority.Value[key] group value by key into keyGroup select new { Key = keyGroup.Key, Value = keyGroup.First() }; </code></pre> <p>However, you're still scanning through the dictionary quite a lot with this. Don't you basically want a reverse map from key to priorities containing that key? That could be constructed much more efficiently. As you say, the example is pretty confusing. If you could tell us what you're trying to achieve in your <em>real</em> code, we may be able to come up with something better. (If it's exactly this situation, I can certainly work on that - I'd rather not do so and then find out that reality is very different though!)</p></li> <li><p>Calling Reverse() will indeed work - but it will buffer all the data. If you want it in reverse order, I suggest you give the SortedDictionary an appropriate IComparer to start with.</p></li> <li><p>Parallel LINQ is "interesting" when it comes to order. It may be different right now, but I <a href="http://msmvps.com/blogs/jon_skeet/archive/2007/12/04/a-cautionary-parallel-tale-ordering-isn-t-simple.aspx" rel="nofollow noreferrer">had fun a while ago</a> when I was plotting the Mandelbrot set using it...</p></li> </ol>
 

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