A Discovery in Linq: Lookup
I've been using Linq to Objects for quite some time - so it was quite a surprise to me when I discovered something new recently - the LookUp class.
LookUp is much like the more familiar Dictionary class, but with a few differences that make it easier to use with Linq.
- Doesn't require unique keys - there can be multiple instances with the same key. When you lookup a key, the result is a sequence of values;
- If you index with a key that isn't there, you get a sequence with zero elements, not an exception.
- Immutability - an instance of
LookUpis created fully formed, with all instances, by theEnumerable.ToLookup()factory extension method.
It seems to me that LookUp addresses the major deficiencies of the Dictionary class, giving us a better tool to use. I know I'll be making frequent use of LookUp in my own code.

Recent comments
4 weeks 15 hours ago
4 weeks 21 hours ago
4 weeks 1 day ago
4 weeks 1 day ago
8 weeks 1 day ago
9 weeks 16 hours ago
9 weeks 4 days ago
9 weeks 4 days ago
11 weeks 5 days ago
12 weeks 3 hours ago