ILookup vs. IGrouping

前端 未结 3 477
暖寄归人
暖寄归人 2020-11-28 23:15

I\'ve been having trouble articulating the differences between ILookup and IGrouping, and am curious if I understand it correctly now. L

3条回答
  •  温柔的废话
    2020-11-29 00:08

    There is another important difference between ILookup and IDictionary: the former enforces immutability in the sense that here are no methods for changing the data (except when the consumer performs an explicit cast). By contrast, IDictionary has methods like "Add" which allow changing the data. So, from the perspective of functional-programming and/or parallel programming, ILookup is nicer. (I only wish there was also a version of ILookup that assigns only one value to a key rather than a group.)

    (Btw., it seems worth pointing out that the relationship between IEnumerable and IList is somewhat similar to the one between ILookup and IDictionary - the former is immutable, the latter is not.)

提交回复
热议问题