0

So i have the exact same code (a couple of lines) in visual studio 2022, on anycpu. In one project i have "Prefer 32-bit".

This is the code:

System.Collections.Hashtable hashtable = new System.Collections.Hashtable();
hashtable.Add("cccccc", 1);
hashtable.Add("dddddd", 2);

So if i use a hashtable and look at its contents (or try to use the enumerator to parse its elements) i can see that they are in a different order.

I know that if i want to use an order i should use a List, or something else, but why is this happening ?

Why does using "Prefer 32-bit" change the order of the elements in the Hashtable ?

The running code side by side

Andrei
  • 19
  • 3
  • The value returned by GetHashCode is not guaranteed to be consistent between executions, let alone under different architectures; the ordering of a HashTable isn't supposed to be relevant anyway :) – Mathieu Guindon Jul 09 '22 at 14:01
  • See https://stackoverflow.com/a/15176541/1188513: it appears the implementation is architecture-dependent. – Mathieu Guindon Jul 09 '22 at 14:03
  • @MathieuGuindon So i will try to look into it, but why is the GetHashCode method relevant in the way the objects show up in the hashtable ? – Andrei Jul 09 '22 at 18:13
  • 1
    I think i found out. It uses that method. https://referencesource.microsoft.com/#mscorlib/system/collections/hashtable.cs,72beea02a81d95fb I forgot that all these classes are available online. – Andrei Jul 09 '22 at 18:18

0 Answers0