Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://msdn.microsoft.com/en-us/library/xfhwa508.aspx"><code>Dictionary&lt;K,V&gt;</code></a> does <em>not</em> have an ordering. Any perceived order maintenance is by chance (and an artifact of a particular implementation including, but not limited to, bucket selection order and count).</p> <p>These are the approaches (just using the <a href="http://msdn.microsoft.com/en-us/netframework/aa569603.aspx">Base Class Libraries BCL</a>) I know about:</p> <ol> <li><a href="http://msdn.microsoft.com/en-us/library/bb460184.aspx"><code>Lookup&lt;K,V&gt;</code></a> <ul> <li>.NET4, immutable, can map keys to multiple values (watch for duplicates during building)</li> </ul></li> <li><a href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.ordereddictionary.aspx"><code>OrderedDictionary</code></a> <ul> <li>Old, non-generic, expected Dictionary performance bounds (other two approaches are <code>O(n)</code> for "get(key)/set(key)")</li> </ul></li> <li><code>List&lt;KeyValuePair&lt;K,V&gt;&gt;</code> <ul> <li>.NET2/3 okay, mutable, more legwork, can map keys to multiple values (watch for duplicates in inserts)</li> </ul></li> </ol> <p>Happy coding.</p> <hr> <p>Creating a hash data-structure that maintains insertion order is actually only a slight modification of a standard hash implementation (Ruby hashes now maintain insertion order); however, this was not done in .NET nor, more importantly, is it part of the Dictionary/IDictionary contract.</p>
 

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