Search code examples
c#resx

Looping through RESX file, items not in order


I am looping through a resx file, using the method described here in the accepted answer here: Loop through all the resources in a .resx file

But the items are not being read in the order that they are in the resx file which is what I would have expected. The ordering is not random and is preserved between reads, but is returned:
Line3
Line2
Line1
Line6
Line5
Line4


Solution

  • Dictionary/Hashtabels do not preserve order of elements. There also no guarantees that order will be the same between run-time versions, x86/x64/other flavors or even runs of the same binaries (also usually order stays the same).

    ResourceSet Class

    The ResourceSet class enumerates over an IResourceReader, loading every name and value, and storing them in a Hashtable. A custom IResourceReader can be used.