ILookup vs. IDictionary

How is the interface ILookup<key, value> different from IDictionary<key, value> ?

I do not understand what ILookup .

+60
c #
Mar 25 '11 at 18:03
source share
2 answers

ILookup entries can contain multiple elements for each key - each key is mapped to an IEnumerable<TElement> .

As outlined in the comments, ILookup unchanged, while you can update the values ​​in an IDictionary (it provides the Add() method and an index that allows you to get settings and values).

In short, their use case is very different - you use the search when you need a 1: N map with values ​​that are fixed and will not (and cannot) change. On the other hand, the dictionary offers a variable mapping of key value pairs 1: 1, so it can be updated to add or remove values.

+87
Mar 25 2018-11-18T00:
source share

It is much simpler than IDictionary . It is used by Linq. It has only Contains , Item and Count . IDictionary has Add , Remove , etc.

+2
Mar 25 2018-11-18T00:
source share



All Articles