One-to-many mappings

A lot of times I had to look for a data structure to store one to many relationships such as a list of products keyed by their categories. I remember the last time I coded in C++ I used a whole lot of std::multimap to do just this.

With C#, there isn’t such a container. The only way is to construct your own container by creating some sort of Dictionary<Key, List>.

Better still, if you only need to add elements once you can just use a simple List<data>, add your data by List.Add() then make a LINQ call to List.ToLookup(). And you immediately have a one to many mapping. This is much more elegant since you do no need to check the dictionary for existing key each time you want to add data.