LinkedHashMap in .NET

Just to clarify a bit for readers: LinkedHashMap only behaves that way when built with one particular constructor overload. Normally the elements are maintained in insert order. (This feels a little odd to me, but never mind.)

I don’t believe there’s any such class in .NET. It wouldn’t be too hard to build one, using a linked list of elements and a dictionary from key to linked list node. Access would then consist of fetching the linked list node, moving it to the head, and returning the value.

I’d be happy to implement it tonight or tomorrow if you want – although probably not with full unit tests etc. (Fully testing a collection is a time-consuming business!)

Leave a Comment