I still use Wintellect’s PowerCollections library, even though it is aging and not maintained because it did a good job covering holes left in the standard MS Collections libraries. But LINQ and C# 4.0 are poised to replace PowerCollections…
I was very happy to discover System.Linq.Lookup because it should replace Wintellect.PowerCollections.MultiDictionary in my toolkit. But Lookup seems to be immutable! Is that true, can you only created a populated Lookup by calling ToLookup?
Yes, you can only create a
Lookupby callingToLookup. The immutable nature of it means that it’s easy to share across threads etc, of course.If you want a mutable version, you could always use the Edulinq implementation as a starting point. It’s internally mutable, but externally immutable – and I wouldn’t be surprised if the Microsoft implementation worked in a similar way.
Personally I’m rarely in a situation where I want to mutate the lookup – I would prefer to perform appropriate transformations on the input first. I would encourage you to think in this way too – I find myself wishing for better immutability support from other collections (e.g.
Dictionary) more often than I wish thatLookupwere mutable 🙂