关于System.Linq.Lookup类 [英] About System.Linq.Lookup class

查看:47
本文介绍了关于System.Linq.Lookup类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读一本C#书时碰到了这堂课,并且有一些疑问.

I came across this class while reading a C# book and have some questions.

  • 为什么将此添加到System.Linq命名空间而不是通常的Collections命名空间?
  • 这堂课的目的是什么
  • 为什么此类不用于直接实例化?这只能通过ToLookup扩展程序使用,对吧?

推荐答案

类的目的:一个键可以映射到多个值的字典.认为它是用于分组而不是一对一映射.

Purpose of the class: a dictionary where a key can map to multiple values. Think of it as being for grouping rather than one-to-one mapping.

仅通过ToLookup决定:通过.再次,对我来说似乎是一个坏电话.另一方面,这意味着结果对于外界是不可变的,这是相当不错的.当然,编写自己的支持该功能的集合很容易-但是适当地"将其包含在集合中将是非常不错的.我的猜测是,MS没有时间/金钱来进行使其成为一流收藏决策所需的相当严格的设计/测试.

Only through ToLookup decision: Pass. Again, seems like a bad call to me. On the other hand, it means that the result is immutable to the outside world, which is quite nice. It's quite easy to write your own collection which supports this, of course - but it would be have been quite nice to have it in the collections "properly". My guess is that MS didn't have the time/money to go through the pretty rigorous design/test required to make it a first class collections decision.

命名空间决定:可能与上述有关.在System.Collections.Generic中拥有一个您自己无法创建的版本会有些奇怪.

Namespace decision: Probably related to the above. Having a version in System.Collections.Generic which you couldn't create yourself would have been a bit odd.

这篇关于关于System.Linq.Lookup类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆